BMP to grayscale image?
15 次查看(过去 30 天)
显示 更早的评论
Hello Sir!
I am writing a gray scale image using: imwrite(gray,'exp.bmp') I want the exact gray scale image back from the bmp image. How can i do this?
or please tel me how can I export a gray scale matrix as image and get it back losslessly?
0 个评论
采纳的回答
Walter Roberson
2011-1-22
If your gray scale matrix is uint8 data class, that is what will happen automatically for BMP files.
If your gray scale matrix is double precision data in the range 0 to 1, then what you want to do cannot be done with BMP files. BMP files are restricted to 1 bit per pixel, 8 bits per pixel, or 24 bits deep (i.e., 3 components each 8 bits per pixel). Double precision gray scale images will be scaled by a factor of 255 and the 8 bits of the integer part of the result will be stored. This will lose precision unless all of your data happens to be integer multiples of 1/256 .
The PNG file format can support 16 bit grayscale images, which refines the precision to integer multiples of 1/65536
If you use the PPM file format, then you might be able to use 'Encoding', 'ASCII', 'MaxValue', 2^53 . That would get you access to the full double precision mantissa bits, but if you had gray values less than 1/2^53 then you would lose those values even though they are easily representable in double-precision numbers.
At least as of 2008b, there is no image file format documented as being able to handle full 64 bit double precision gray scale images, so if that is the kind of data you have, either you have to accept some loss, or you have to store the data in the file in such a way that although the file holds all of the data, the image you see would not be viewable without special software.
更多回答(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!