user366312
user366312

Reputation: 17026

Showing multiple images in one window in Matlab

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 

enter image description here

How can I solve the issue?

Upvotes: 0

Views: 148

Answers (1)

Sardar Usama
Sardar Usama

Reputation: 19689

The problem here is that your image is of uint8 class but you're storing it in a 3-D array of double class. In this double class array, you have values greater than 1 which get interpreted as white.

You need to either convert your original image I to double (i.e I= im2double(I);) or convert J to uint8 i.e. J = uint8(J);.

Upvotes: 3

Related Questions