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

@Chen Ji: please show us the outputs of these commands:
class(Lena)
max(Lena(:))
Chen Ji
Chen Ji 2018년 3월 1일
Oh! I worked out caz i found that the input matrix for imwrite should in [0,1] and my Lena element range is in [0,255]. Then i divide each element by 255 and then it worked. It should be a correct solution, right? Thx!!!
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일

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')

카테고리

도움말 센터File Exchange에서 Denoising and Compression에 대해 자세히 알아보기

태그

질문:

2018년 3월 1일

댓글:

2018년 3월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by