Reading Direct from Disk or Image
Afficher commentaires plus anciens
I need to read in binary data directly from a hard drive that's connected to my computer, but which is in a format that is not recognized by any OS. How would I access this directly in Matlab?
The drive is a 120 GB hard drive interfaced via PATA/IDE to a USB/IDE adapter.
Réponses (2)
Ashish Uthama
le 8 Juin 2011
1 vote
I assume the file in the drive is accessible to your OS.
You can try using fopen and fread to read binary data into MATLAB. However, you need to find out some more information about your image file:
- datatype - What constitutes a pixel in this format? i.e is it uint8, uint16 or x-bits per pixel
- dimensions - What are the image dimensions. When you read binary data, it is essentially a 1D stream. You would have to know the dimensions to reorganize it to a MxN grayscal image or a MxNx3 color image or similar.
If you dont know the above (in the least). Post some more information here which might help us give you more helpful answers. For example:
- Source of the image. How did it get on the disk? Did you get them from a device (microscope, camera etc?). If so, which one? Are they the output of a software program? (Again.. if so, which? :)).
- What is it supposed to represent?
- What do you plan to do with it?
- What is its file extension?
2 commentaires
Pete Marchetto
le 8 Juin 2011
Walter Roberson
le 8 Juin 2011
Are there some kind of time-stamps mixed in?
Walter Roberson
le 8 Juin 2011
Are you restricted to Windows? Or could you use Linux (or Mac OS-X) ?
I do not know the Windows equivalent, but in Unix-based systems, you would connect the device, and look under /dev to find the proper name for it. You would be looking for a name with "rdsk" or "rdisk" in it, probably. For example,
$ ls -l /dev/*disk0
brw-r----- 1 root operator 14, 0 24 May 09:03 /dev/disk0
crw-r----- 1 root operator 14, 0 24 May 09:03 /dev/rdisk0
The line that starts with 'c' ("character device") is the one you want.
In MATLAB, fopen() the device for binary reading:
fid = fopen('/dev/rdisk0','r');
You can then use
indata = fread(fid, N, '*uint16');
where N is the number of values you want to read at one time.
After that, probably the fastest is to divide the values by 16 to shift them right.
4 commentaires
Pete Marchetto
le 8 Juin 2011
Walter Roberson
le 8 Juin 2011
The above listing was taken from OS-X ;-)
Does the device show up in /dev for you? If not are you able to find it in the System Profiler ?
Pete Marchetto
le 9 Juin 2011
Walter Roberson
le 9 Juin 2011
What permissions does the /dev name have? In the above example, only user "root" or a process with root privileges would be able to open the device file directly. You might have to
sudo chmod go+r /dev/rdisk2
in order to get access from an unprivileged account.
As this is a USB connected device, it would not entirely surprise me if the /dev entry got deleted when the device was disconnected. If so, then probably by default when it got reconnected the new /dev entry would not have the permissions you want. I seem to recall there being a way to configure those permissions, but I do not recall now what it is and I don't know if what I am recalling was ever implemented for OS-X.
You might find it necessary either run as a privileged user, or to create a suid executable that changed the permissions for you on demand.
Catégories
En savoir plus sur Marine and Underwater Vehicles dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!