Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange/Magical Image visualization with Matlab

I have an Image of double, I want to show it with unsigned int 16 bit, so I do:

I = im2uint16(I);
figure;imshow(I);title('Image being saved')

This shows this (with its normal noise):

Now I want to write this image with .png with Bit Depth 16 Bit. I do:

imwrite(I,'image.png','BitDepth',16);

And now the image, opened with Photoshop CS5, or Windows Photo Viwer looks like this: (the noise is magically disappeared):

Can someone explain this strange behaviour ?

How to Reproduce this error

Download in C:\test\ the image I used here:

Now run this script:

I = im2double(imread('C:\test\test_matlab.tif'));

% Add gaussian noise with variance = 0.0012
I = imnoise(I,'gaussian',0,0.0012);
figure,imshow(I);

imwrite(I,'C:\test\withNoise.tif');

And compare the figure in matlab versus the file saved

like image 944
dynamic Avatar asked Mar 19 '26 07:03

dynamic


1 Answers

It's difficult to say because you didn't give enough data to reproduce, but I'd guess the problem is related to a display issue: the image is larger than you physical display window, hence some downsampling must be applied to display it. Depending on how that resampling is done, the result can be -in this scenario- very different, visually. Suppose that matlab applies a nearest-neighbour resampling for its display, that would explain why the image looks very noisy; instead, if another image viewer applies a bilinear interpolation or something similar, that would amount to a local average that practically filters out the white noise.

To test this, try the same with a small image. Or try zooming the apparently clean image, to see it at real size (100% : one image pixel = one display pixel)

Update: See also here

like image 167
leonbloy Avatar answered Mar 20 '26 22:03

leonbloy