how to put several image into one figure.

17 views (last 30 days)
mehdi
mehdi on 11 Oct 2014
Answered: Image Analyst on 12 Oct 2014
hi all.
I load a folder that contains 255 'tif' images. I put all images together in one figure, but there are spaces between each image.
Can anyone tell me how to put images without any spaces?
Thanks in advance.
Below shows all images in a plot.
my code is:
folder_name = uigetdir;
f = dir(fullfile(folder_name, '*tif'));
for ii = 1 : length(f)
im = imread(f(ii).name);
subplot(15,15,ii);
colormap(gray);
imagesc(im);
end

Answers (2)

Geoff Hayes
Geoff Hayes on 12 Oct 2014
Mehdi - if all of your images have the same dimension (all are mxn) then you could do something like the following
m = 15; % number of subplots per row
n = 15; % number of subplots per column
hAxes = [];
for u=1:m
for v=1:n
% create the subplot at the given position
hAxes(u,v) = subplot('Position',[(v-1)/n 1-(u/m) 1/n 1/m]);
% add the (dummy) 100x200 image
imagesc(repmat(uint8(randi(255,1,1,3)),100,200,1),'Parent',hAxes(u,v));
% hide the axes ticks, labels, etc.
set(hAxes(u,v),'Visible','off');
end
end
The above just creates a grid of 15x15 subplots, where each plot is just a solid (random) colour. Each plot is positioned in such a way that there is no space between each one. You should be able to place your tiff images in a similar manner.
Else, you could just create one image that is composed of all 225 sub-images, and then display just that image.

Image Analyst
Image Analyst on 12 Oct 2014
Simply use montage() rather than calling subplot 255 times, that is if you have enough memory. If you don't, then you'll have to create an image and paste the images onto it, after downsizing them. See my copy and past demo, attached.

Tags

Community Treasure Hunt

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

Start Hunting!