0

I have a .raw image file that is encoded as uint16. When I open it in ImageJ, I can see the image dimensions immediately.

Now, when I use MATLAB, I use fid = fopen('image1.raw') pixelData = fread(fid,'uint16') fclose(fid)

Now, I have the data in MATLAB, but I have to use ImageJ to get the dimensions of the image to reshape pixelData. How does ImageJ get the dimensions and how can I do the same in MATLAB?

SEU
  • 1,304
  • 4
  • 15
  • 36
  • 1
    Is it a camera raw file? Or one of those raw files that is just a dump of pixel data? Camera raw images do have a header that you need to decode. I assume this is what ImageJ is doing. In this case, `fread` doesn’t just return the pixel data! – Cris Luengo May 29 '22 at 21:17
  • It should have a header. If its just a dump of pixel data, imageJ also doesn't know the size, you need to manually input it. – Ander Biguri May 30 '22 at 10:09
  • If it doesn't have a header, you can use some methods to try to guess the dimensions.... get the filesize in bytes, divide that by the bytes per sample (i.e. by 2 if 16-bit samples) and again by the number of channels (e.g. 3 for RGB). Now get the factors of that number by going to WolframAlpha and entering *"factors of THAT NUMBER"*. Now look for common image sizes in there, and also look for numbers near the square root of THAT NUMBER since images tend to be somewhat square. – Mark Setchell May 30 '22 at 10:16
  • 1
    You can also do all that Mark suggested programatically in MATLAB using the size. – Ander Biguri May 30 '22 at 10:17
  • Another method is to go to the middle of the file (to avoid image edge effects), iterate over common image widths, and test the correlation between each image row and the next and assume the ones with high correlation are more likely to be the correct width. – Mark Setchell May 30 '22 at 10:18
  • If it bothers that much, ImageJ is open source, you can step through the image loading process with a debugger and see exactly what's going on. ;) – X Zhang May 30 '22 at 12:08

0 Answers0