Why got different value when use imread to read a binary image that saved by imwrite??

Hey, to be able to make a binary image, i used I=zeros(256,256); and then i changed some value in I to 1,then use imshow(I) to check the result,it looks good. i got the binary image i want. the i use imwrite(I,'result.jpg','jpg')to save the result, also succeed. here is the problem, i use H=imread('result,jpg'); to read the file, but when I check the H array, i found that the pixel value are not just 0 and 255, they also include like 2, 4,5,9 ,250, 253, these kind of value. why does it changed like this? jpg compression problem? thanks very much

 채택된 답변

Walter Roberson
Walter Roberson 2011년 8월 26일
JPEG artifacts is plausible for the situation you describe.
As a first step I suggest adding 'Mode', 'lossless' to your imwrite() options. If that gets you exactly the image you want, then you know you have artifact problems. If you wanted to take it further than that, you could remove the 'Mode' option again, but add 'Quality' with a number up to 100 (default is 75) to explore the level at which the quality is sufficient for your purposes.

댓글 수: 3

Even the lossless and 100% JPEGs are not guaranteed to be equal due to rounding errors in the DCT.
If you need an exact reconstruction, use PNG, TIFF or GIF.
Yes,even I use 100% quality, they still had some wrong values. Thank you two so much, I got more knowledge about imwrite.
And yes, I decide to use bmp or tiff
Hmmm, I would have guessed 'lossless' would skip the DCT step.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

질문:

wei
2011년 8월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by