Montage of several different images
4 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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
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);
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!