Problem with imwrite a color image
Mostrar comentarios más antiguos
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 comentarios
Geoff Hayes
el 14 de Ag. de 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
el 14 de Ag. de 2018
I don't think you tried my code below, which DOES work.
Angela
el 14 de Ag. de 2018
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 14 de Ag. de 2018
1 voto
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 comentarios
Angela
el 14 de Ag. de 2018
Walter Roberson
el 14 de Ag. de 2018
All you need to do is use .png as the file extension when you imwrite()
Walter Roberson
el 15 de Ag. de 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
el 16 de Ag. de 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
el 16 de Ag. de 2018
Walter Roberson
el 16 de Ag. de 2018
.. So write two copies of the image like I suggested, one archive quality and the other reduced bit depth for speed.
Angela
el 16 de Ag. de 2018
Categorías
Más información sobre Images en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!