How does MATLAB reads an image?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I would like to know how MATLAB reads an input image. Is the in the integer format or the floating point value? Is there any document available? Please give me the reference links.
Thank you.
0 个评论
回答(2 个)
Image Analyst
2017-6-20
It reads it with imread() if it's one of the standard formats that you can see with the "imformats" command. The data class can be uint8, uint16, or double, depending on how it was saved into the file. Or it can be some special format like netcdf or dicom where you get a bunch of metadata back also, in addition to the pixel values.
2 个评论
Image Analyst
2017-6-21
Yes, of course. It will round off the fractional part. Why do you want to save the image? If it's just to use again later with MATLAB (only), then save it in a .mat file with save(). If you need it in another program, I think the TIFF class can save double images.
Walter Roberson
2017-6-21
imwrite() always converts floating point to integer before writing. If you need to write double precision, then use something like,
filename = 'myfile.tif'; %adjust as needed
t = Tiff(filename,'w');
t.setTag('Photometric',Tiff.Photometric.MinIsBlack); % assume grayscale
t.setTag('BitsPerSample',64);
t.setTag('SamplesPerPixel', size(YourImage,3));
t.setTag('SampleFormat' ,Tiff.SampleFormat.IEEEFP);
t.setTag('ImageLength', size(YourImage,1));
t.setTag('ImageWidth', size(YourImage,2));
t.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);
t.write(YourImage);
t.close();
(Thanks to John from https://www.mathworks.com/matlabcentral/newsreader/view_thread/314008 for the key hint I had been missing for years.)
However:
- You will probably not find any image viewer that can display these images, except possibly ImageJ
- In nearly every case I have seen so far in which someone was asking to write double precision images, what was happening was that they were reading in integer images, doing a floating point transformation on them, doing information hiding in the floating point values (watermarking or steganography) doing the inverse transform, and wanting to write the modified data stream to a file "exactly" in order to be able to read the exact coefficients back later -- the 64 bits being necessary because the inverse transform was coming out as non-integer (sometimes including negative values.) Writing out 64 bit floating point in image form is the wrong solution to this situation -- the right solution being to either use an integer to integer transform or else to do the coefficient modifications in a way that after inverse transform and rounding to integer, the new integer coefficients can still have information extracted from them.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!