MATLAB Answers


Image display with uint8 and double

Asked by Mohsin Shah on 20 Mar 2018
Latest activity Edited by Stephen Cobeldick on 11 Sep 2019
Can someone explain why the following image, 'yinyang.png', is displayed differently when I use uint8 and double in the imshow function?
I = imread('yinyang.png');
figure(1), imshow(I); title('image displayed with uint8')
figure(2), imshow(double(I)); title('image displayed with double')
The original image displayed in Windows Photo Viewer and the two figure(1) and figure(2) are attached.


Sign in to comment.

1 Answer

Answer by Stephen Cobeldick on 20 Mar 2018
Edited by Stephen Cobeldick on 11 Sep 2019
 Accepted Answer

It seems that you have a "binary" image with values 0 and 1, which is stored as uint8.
  • Because floating-point images are assumed to contain values between 0 and 1 the double image displays those colors as black and white.
  • But for the uint8 image the values are assumed to be from 0 to 255, so those two colors are shown as black and very-dark-gray (indeed, the symbol is just visible in your screenshot).
You can probably use imshow's optional input argument to specify the (non-default) range:
See also:
Addendum: the PNG standard supports 1-bit (i.e. binary) images, which MATLAB imports as logical images. Logical images are displayed as black-and-white.


I checked it with imshow(double(I),[0,255]) and now both show the same display but why it is not shown the way it is shown in Windows photo viewer?
"why it is not shown the way it is shown in Windows photo viewer?"
We are not responsible for any image color processing, spatial anti-aliasing, or image scaling that might be performed by Windows Photo Viewer, and you should check its documentation. I certainly would not trust it as an accurate representation of an image. Do you?
From the screenshot that you provide it appears that the main difference comes from some spatial anti-aliasing: this means that Photo Viewer "smooths" the edges to make it look nicer for humans to look at... but this means what you see are not the "real" image pixel values. Most likely MATLAB is displaying the pixels "as they really are".
Yes, I agree with you. I think Photo Viewer also do some sort of scaling for making the image appear more prominent and clear.

Sign in to comment.