why the imread output result is not same as the input of the imwrite?
조회 수: 2 (최근 30일)
이전 댓글 표시
if true % code data_test= [1 2 3 4; 2 5 0 6; 4 10 0 3; 5 8 6 14]; imwrite((data_test),'clown.png'); s=imread('clown.png') end run the code above,i get that s =
255 255 255 255
255 255 0 255
255 255 0 255
255 255 255 255
If i turn the data type of data_test to uint8,(imwrite(uint8(data_test),'clown.png');) the result of s is same as data_test. why the input of imwrite must turn to uint8? thank you very much.
댓글 수: 0
채택된 답변
Guillaume
2014년 10월 8일
When pixels are of type double, as is the cas for your data_test, intensities are assumed to be in the range 0-1. Anything below 0 is considered the same as 0, anything above 1 is considered to be 1.
Thus, when you save your data_test as double, it is just converted to: [1 1 1 1; 1 1 0 1;1 1 0 1; 1 1 1 1]. As PNG images don't support double pixels, it is then converted to uint8. Hence why, you get the result back as uint8.
Note that im2uint8 produces the same result:
im2uint8(data_test)
Now, the uint8 function is not designed for images but just for plain number, and will convert any number in the range 0-255 to unsigned 8 bit integer with the same value. Therefore there is no clipping. Compare the above with:
im2uint8(uint8(data_test))
In conclusion, if your pixels are indeed uint8, declare them as so, otherwise matlab will consider them to range from 0 to 1.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!