Images obtained by GAN could not be shown

1 view (last 30 days)
S C.Carl
S C.Carl on 14 Jun 2022
Edited: S C.Carl on 15 Jun 2022
I run the codes at which generates 25 new images and shows the generated images after tiling and scaling by this;
I = imtile(extractdata( dlXGeneratedNew ));
I = rescale(I);
But, I want to show each generated image (separately) without tiling and scaling, and to put them into the array called Images(224,224,3,25). So, I have written this;
rows = 5; columns=5; ind=1;
% Get size of 1
row1 = rows/5;
col1 = columns/5;
for col = 1 : 5
leftCol = (col-1) * col1 + 1;
rightCol = leftCol + col1 - 1;
for row = 1 : 5
topRow = (row-1) * row1 + 1;
bottomRow = topRow + row1 - 1;
thisImage = I(topRow:bottomRow, leftCol:rightCol, :);
figure(ind); imshow(thisImage);
Images(:,:,:,ind) = thisImage;
ind = ind + 1;
Here, thisImage returns as 1x1x3 single array. So, its size and format is different from an input image, which is 224x224x3 uint8.
Could you please help me to solve this problem

Answers (1)

Hiro on 15 Jun 2022
I belive the lines
I = imtile(extractdata( dlXGeneratedNew ));
I = rescale(I);
are not behaving as you would expect.
The function imtile accepts multiple files and put them into a small image. So you should remove it as follows:
I = extractdata( dlXGeneratedNew );
img = I (:,:,:,idx)
igm = rescale(img);
where idx represent the index of the image of your interest.
  1 Comment
S C.Carl
S C.Carl on 15 Jun 2022
Edited: S C.Carl on 15 Jun 2022
Thank you Hiro.
I have one more question: The GAN example generates 25 images and uses 5 classes of flower images.
I want to generate 1260 images and to use 7 classes (each class includes 60 images, so there are 7x60=420 orijinal images. I want to generate 3 times of the orijinal images, i.e., 3x420 = 1260)
So, running the GAN example 50 time to generate about 1260 images means construction the GAN 50 times for each running, which will be time consuming.
So, should I run the GAN example by changing only these? :
numValidationImages = 49; % instead of 25;
numObservations = 1260; % instead of 25;
To be able to generate equal number of images from each class, should be the following codes updated or not?
ZValidation = randn(numLatentInputs,numValidationImages,'single');
Z = randn(numLatentInputs,miniBatchSize,'single');
ZNew = randn(numLatentInputs,numObservations,'single');

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!