Reading Direct from Disk or Image

2 visualizzazioni (ultimi 30 giorni)
Pete Marchetto
Pete Marchetto il 8 Giu 2011
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.

Risposte (2)

Ashish Uthama
Ashish Uthama il 8 Giu 2011
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 Commenti
Pete Marchetto
Pete Marchetto il 8 Giu 2011
The disk is from an MARU (Marine Autonomous Recording Unit), which is an acoustic recorder. The data is a bitstream where each sample is 16 bits in length, and consists of a 12-bit ADC output (left-justified) followed by four 0-value padding bits. The ADC's output is simply the sample value relative to some analog reference voltage (2.048 VDC) and is unsigned.
Walter Roberson
Walter Roberson il 8 Giu 2011
Are there some kind of time-stamps mixed in?

Accedi per commentare.


Walter Roberson
Walter Roberson il 8 Giu 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 Commenti
Pete Marchetto
Pete Marchetto il 9 Giu 2011
I can see it in /dev, but I get fid=-1 for any fopen that I use on it.
Walter Roberson
Walter Roberson il 9 Giu 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.

Accedi per commentare.

Categorie

Scopri di più su Marine and Underwater Vehicles in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by