How can I read in a RAW image in MATLAB?

Your row/col sizes are reversed. Since MATLAB arrays are column-major, and raster images are usually stored row-major, you need to read the image as a [col row] matrix, then transpose it.

row=576;  col=768;
fin=fopen('m-001-1.raw','r');
I=fread(fin, [col row],'uint8=>uint8'); 
Z=I';
k=imshow(Z)

The image replication is happening because you’re short 768-576 = 192 pixels per line, so each line is progressively off that amount. After 4 lines, you’ve made up the difference (4*192 = 768), so you have a 4-image replication.

Leave a Comment