How do I remove the spaces between concatenated images. they are too wide but i want the image to appear as 1 after concatenation

1 view (last 30 days)
a='C:\Users\rutat\OneDrive\Documents\MATLAB'
b=dir(fullfile(a,'*.jpg'))
c=numel(b)
for d=c:-1:1
image = imread ( sprintf('image%d.jpg',d));
x=subplot(1,c,d)
imshow(image,'parent',x)%accesible objects shown here
end

Answers (1)

DGM
DGM on 17 May 2022
Edited: DGM on 17 May 2022
Depending on what your needs are, you can use montage(), imtile(), or something else.
Instead of trying to display images one at a time, read them and store them in a cell array.
filenames = {'peppers.png','football.jpg','cameraman.tif','llama.jpg'};
nfiles = numel(filenames);
imstack = cell(nfiles,1);
for f = 1:nfiles
imstack{f} = imread(filenames{f});
end
% you could use montage()
montage(imstack); % result is 1080x1440
% or you could use imtile()
figure
outpict = imtile(imstack); % result is 768x1024
imshow(outpict)
Note that in both these cases, the images are not shown on a common scale. Depending on the size and number of your images, you may notice that they've been downscaled.
If you want to enforce a certain size, you can play with the 'thumbnailsize' parameter for either function. This is mostly useful if your images are all the same size. If they aren't the same size, you might have to make some compromises between scaling and good use of space.

Categories

Community Treasure Hunt

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

Start Hunting!