Problem with imwrite a color image
显示 更早的评论
I am trying to save the output color image of a program as a jpg or png file. I have tried
outfile='image.jpg'
imwrite(im2uint16(Image),outfile,'BitDepth',12,'Mode','lossless','Quality',100)
When i tried to open this using Gimp or ImageMagick , the image could not open, it was not recognized. Can anyone suggest the right way to save a color image as a jpg using imwrite? Thank you.
4 个评论
Geoff Hayes
2018-8-14
Angela - what is the data type for your image, Image? Is it necessary to convert to 16-bit unsigned integers? Perhaps try
imwrite(Image, 'image.jpg', 'jpg');
Image Analyst
2018-8-14
I don't think you tried my code below, which DOES work.
Angela
2018-8-14
采纳的回答
更多回答(1 个)
Walter Roberson
2018-8-14
1 个投票
JPEG does not support 16 bit images. Some JPEG libraries support 12 bit images.
JPEG XR supports 16 bit images, but MATLAB does not support JPEG XR.
8 个评论
Angela
2018-8-14
Walter Roberson
2018-8-14
All you need to do is use .png as the file extension when you imwrite()
Walter Roberson
2018-8-15
Then you will need to get JPEG to change the JPEG standard to permit higher bit depths, and then wait for MATLAB to pick up on the revised standard.
This is rather unlikely to happen.
Image Analyst
2018-8-16
The reason jpg is smaller is that it's smaller when you compress more and throw away information. The two lossless formats are bigger because no information is lost. In these days of terabyte solid state drives and 3 GHz computers why are you worried about saving a few kilobytes of drive space? You should be more worried about the fidelity of your image data. Don't save junk just to save a few kilobytes that really won't even matter or make a difference in anything.
Angela
2018-8-16
Walter Roberson
2018-8-16
.. So write two copies of the image like I suggested, one archive quality and the other reduced bit depth for speed.
Angela
2018-8-16
类别
在 帮助中心 和 File Exchange 中查找有关 Images 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!