Montage of several different images

4 views (last 30 days)
John Doe
John Doe on 31 Mar 2019
Commented: Geoff Hayes on 1 Apr 2019
Function montage_images(X, Y) where X is a M-by-D data matrix (of floating-point numbers in double-precision format, which is the default in Matlab), where M is the number of samples, and D is the the number of elements in a sample. Note that each sample is represented as a row vector rather thana column vector. Y is a M-by-1 label vector (of uint8) for X. Y(i)is the class number ofX(i,:) which are just class labels
So, I've loaded in the dataset (not shown) and there's ten sets of this, of which I need to create a montage of the first 10 samples of each set. So, I have two for-loops and I've managed to get the images, but I'm stuck on how to compile each set of 10 images and then making it display with montage. It seems that montage doesn't play nicely with image format or something?
The X = Xtrn2(Y==k, :) gets the associated set # (1,2, .., 10).
Any help/hints would be greatly appreciated.
55618380_326336761413541_5738513565191503872_n.png

Answers (1)

Geoff Hayes
Geoff Hayes on 31 Mar 2019
From montage, the input parameter can be list of filenames or a list of images. You are providing (if I understand your code) a (single) graphics object or handle to an image. I think that you want to create the images first and then provide this list of images to the function montage. Your code would then look something like
myImages = cell(1,10);
for k = 1:10
myImages{k} = reshape(X(k,:)*255.0, 28, 28)';
end
montage(myImages);
The above may work (I haven't tested it) but hopefully it will give an idea of why your code may not be working as expected.
  2 Comments
John Doe
John Doe on 1 Apr 2019
Is it possible to open all 10 different montages in their own separate windows at once? After implementing this snippit, it opens all of them, but it quickly flashes through all of them in one single window and finishes on the last set of 10 images montage.
Thanks
Geoff Hayes
Geoff Hayes on 1 Apr 2019
You can try adding a call to figure before your call to montage:
myImages = cell(1,10);
for k = 1:10
myImages{k} = reshape(X(k,:)*255.0, 28, 28)';
end
figure;
montage(myImages);

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!