I am trying to read some data from a file, and output it as just raw data. The file is an image, and the output file I am writing data 1 row at a time.
In matlab, I do the following:
bin_path = 'myfile.bin';
m = memmapfile(bin_path, 'Format', {'uint16', [5000 5000], 'im'});
disp(m)
figure, imagesc(m.Data.im), colormap(gray)
To try to display the data, thinking I'd get an image. However, it is not an image, it is just a bunch of black and gray and white lines.
Is the matlab portion of this set up correctly?
This looks like it might work, if your file consists of exactly 5000x5000x2 bytes, each representing a pixel in a square image. Using memmapfile
is unusual--in fact, I didn't even know that function existed in Matlab. It would be much more typical to simply use fread
to read a raw image. If your image is in a standard file format (JPG, PNG, etc), use imread
.
Assuming that your image is really 5000 x 5000 x uint16, you might be suffering from an endianness problem. Try using fopen
and fread
to get the data; Matlab's fopen
accepts an argument telling it whether to do endianness translation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.