How do these image bit conversions work??

So this is a basic question on image conversion algorithms.
If I load an image.
img = imread('peppers.png');
img = rgb2gray(img);
and then convert it back forth from 8 bit to 16 bit several times;
img = im2uint16(img);
img =im2uint8(img);
for like 10 times or so. The final resulting image seems exactly the same. That seems a bit odd to me, shouldn't there be some rounding errors when converting from 16-bit to 8-bit? That information should have been lost right? And shouldn't each iteration of this conversion amplify the error?
I am using MATLAB 2017b so its entirely possible that older versions of matlab may not do this...

 채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 7일

0 개 추천

im2uint16() notices that the input is uint8, and multiplies the input by a constant number to get the 16 bit version. The number it multiplies by is 257. This is the same thing as duplicating the bytes -- for example byte 0xD8 gets changed to 0xD8D8
im2uint8() applied to a uint16 image works by just dropping the last byte.
You can see that a cycle of these involves duplicating bytes and dropping them, which is going to leave you with the original bytes.

댓글 수: 1

Nick
Nick 2017년 11월 7일
Oh thats right, I was multiplying things by 256 and wondering why everything was off.

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

추가 답변 (0개)

카테고리

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

태그

질문:

2017년 11월 7일

댓글:

2017년 11월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by