Why do certain images require imshow(imagename,[]). whereas others don't?

2 views (last 30 days)
In the following code, the convolved images require imshow(imagename,[]), whereas the original image (A) does not require the '[]' in imshow() to display it. I don't understand the reason behind why one image require this, and the other doesn't.
A=imread('cameraman.tif');
PSF = fspecial('gaussian',[5,5],2);
h=fspecial('motion', 10, 45);
B=conv2(PSF,A);
C=imfilter(A,h,'replicate');
D=conv2(A,A);
subplot(2,2,1), imshow(A);
subplot(2,2,2), imshow(B,[]);
subplot(2,2,3), imshow(C,[]);
subplot(2,2,4), imshow(D,[]);
I have gone through the documentation of imshow(), but I don't understand the reason behind this behavior.

Accepted Answer

Jonas
Jonas on 27 Jun 2022
the answer loes within the variable class. the original inage is uint8 which can have values between 0 and 255, this means imshownautomatically uses 0 to 255 to interpret. by doing calculations on the uint8 without previous conversion from uint8 to double, the resulting pixels for e.g. B are also between 0 and 255, but as double. And double images are nornally in the range between 0 and 1, since most values are greater than 1, the resulting image is white everywhere. you could either tell imshow to use 0 to 255 as borders for the double images manually, or you could could cast be to uint8 ( uint8(B) ), then imshow uses the border automatically.
pay attention, that calculations on images can change the range of you numbers, throwing uints8 outside their normal range as double. there you have to decide, hiw you want to process those values

More Answers (1)

KSSV
KSSV on 27 Jun 2022
Edited: KSSV on 27 Jun 2022
You check the class of A, B.
A=imread('cameraman.tif');
PSF = fspecial('gaussian',[5,5],2);
h=fspecial('motion', 10, 45);
B=conv2(PSF,A);
whos A B
Name Size Bytes Class Attributes A 256x256 65536 uint8 B 260x260 540800 double
The class of A is uint8, and the class of B is double. So, you need to specify []. If you don't want to specify, you may convert double to uint8 using
B = uint8(B) ;
imshow(B)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!