Problem with imwrite a color image

15 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2018-8-14
I don't think you tried my code below, which DOES work.
Angela
Angela 2018-8-14
Thank you for your answer. Please see below my comment underneath your answer. Although the code you suggested works and saves an image as an jp2, what i want is an image saved as jpg (or png) because jp2 images can not be opened by ImageMagick or Gimp.Thank you.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2018-8-14
Photoshop doesn't recognize it either. But this works:
rgbImage = imread('peppers.png');
outfile='image.jp2' % JPEG 2000
imwrite(im2uint16(rgbImage),outfile,'Mode','lossless')
And I'd recommend you use PNG rather than JPG or JPEG2000 (jp2).
PNG has pretty much become the widespread de facto standard.
  8 个评论
Walter Roberson
Walter Roberson 2018-8-15
编辑:Walter Roberson 2018-8-15
writejpg>set_jpeg_props would never be called for file extension .png .
If you go the dual-file route, then
imwrite(im2uint16(rgbImage), 'newimage.png'); %for archive quality
imwrite(im2uint8(rgbImage), 'newimage.jpg'); %for quick access that is not archive quality
Angela
Angela 2018-8-16
Thank you. The png worked but unfortunately the jpg still needed the bitdepth. I tried to use the 'Quality' switch but it also did not seem to have saved a smaller image. So for now i went the dual route with png and a jpg with a 'lossy' option.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2018-8-14
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 个评论
Walter Roberson
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
Angela 2018-8-16
Thank you for your help Walter Roberson, that is what i ended up doing.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by