Showing multiple images in one window in Matlab
1 次查看(过去 30 天)
显示 更早的评论
Why doesn't the following code show the images?
clear all;
image_name = 'woman.png';
I = gray_imread(image_name);
N = 12;
J = zeros(size(I,1), size(I,2), N);
for i=1:N
J(:,:,i) = I;
end
sqrtt = ceil(sqrt(N));
m = sqrtt;
n = sqrtt;
for k=1:N
K = J(:,:,k);
subplot(m,n,k);
imshow(K);
set(gca,'xtick',[],'ytick',[])
end
How can I solve the issue?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/166128/image.png)
2 个评论
采纳的回答
Walter Roberson
2017-7-28
Change
J = zeros(size(I,1), size(I,2), N);
to
J = zeros(size(I,1), size(I,2), N, class(I));
2 个评论
Walter Roberson
2017-7-28
You are accidentally converting uint8 values to double with the same integer values. However MATLAB looks at the data type to determine the expected range of values. For the integer data types like uint8 the smallest integer of the type is mapped to the first color in the color map and the highest valid integer for the type is mapped to the last color in the map. For the floating point types the rule is different: 0 is mapped to the first colour and 1 is mapped to the last colour. So where uint8(128) would map halfway between into the colour map, double(128) is way outside the expected 0 to 1 range and so would get mapped to the last colour. You end up with an image that is black where the original was exactly 0 and bright white everywhere else.
The change to the code that I showed does not initialize J as double (the default when you use zeros), and instead copies the data type such as uint8 from the original matrix to J so that the original and J will be treated the same way by the graphics engine.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!