Problem with imwrite a color image
Show older comments
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 Comments
Geoff Hayes
on 14 Aug 2018
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
on 14 Aug 2018
I don't think you tried my code below, which DOES work.
Angela
on 14 Aug 2018
Accepted Answer
More Answers (1)
Walter Roberson
on 14 Aug 2018
1 vote
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 Comments
Angela
on 14 Aug 2018
Walter Roberson
on 14 Aug 2018
All you need to do is use .png as the file extension when you imwrite()
Walter Roberson
on 15 Aug 2018
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
on 16 Aug 2018
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
on 16 Aug 2018
Walter Roberson
on 16 Aug 2018
.. So write two copies of the image like I suggested, one archive quality and the other reduced bit depth for speed.
Angela
on 16 Aug 2018
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!