Why do certain images require imshow(imagename,[]). whereas others don't?
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Jonas
2022-6-27
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
更多回答(1 个)
KSSV
2022-6-27
编辑:KSSV
2022-6-27
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
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!