Why imwrite doesn't work??

9 次查看(过去 30 天)
Chen Ji
Chen Ji 2018-3-1
评论: Chen Ji 2018-3-1
I have a .mat file of Lena(greyscale) and i want to use imwrite to trnsfer it to a jpeg file. so i used:
load Lena;
imwrite (Lena, 'lena.jpg')
there is a jpeg file being generated but it is all white (all values are 255). I don't know why is that?
  4 个评论
Stephen23
Stephen23 2018-3-1
编辑:Stephen23 2018-3-1
"found that the input matrix for imwrite should in [0,1] "
This is not correct: the input range actually depends on the image data class. If you have an image of class double then dividing by 255 may work, see my answer for another solution.
Chen Ji
Chen Ji 2018-3-1
I used the code in your answer and the commend is "double" and 240

请先登录,再进行评论。

回答(1 个)

Stephen23
Stephen23 2018-3-1
编辑:Stephen23 2018-3-1
Your image has double values on range [0,255], so you need to scale the values to [0,1] or change the class:
imwrite(uint8(Lena), 'lena.jpg')
imwrite(Lena/255, 'lena.jpg')

类别

Help CenterFile Exchange 中查找有关 Denoising and Compression 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by