The difference between uint8 and double images when using imshow

6.6k views Asked by At

The following code snippet results a double image.

f = imread('C:\Users\Administrator\Desktop\2.tif');
h = double(f);
figure;
imshow(h);

whereas, this other code snippet results a uint8 image.

f = imread('C:\Users\Administrator\Desktop\2.tif');
figure;
imshow(f);

While displaying these two figures, the displayed results of these two images using imshow are different, but what is the reason behind this difference?

1

There are 1 answers

1
Suever On BEST ANSWER

Images of type double are assumed to have values between 0 and 1 and uint8 images are assumed to have values between 0 and 255. Since your double data contains values between 0 and 255 (since you simply cast it as a double and don't perform any scaling), it will appear as mostly white since most values are greater than 1.

You can use the second input to imshow to indicate that you would like to ignore this assumption and automatically scale the display to the dynamic range of the data

imshow(h, [])

Or you can normalize the double version using mat2gray prior to displaying the image

h = mat2gray(h);
imshow(h)