Clear Filters
Clear Filters

"tighter" tile spacing and uniform tile height using tiledlayout?

60 views (last 30 days)
I have three .png images (.fig also available) that I would like to combine using a tiledlayout.
I want the combined image to have a 1x3 layout and have a much tighter spacing than the "tight" option is giving, but I don't want no spacing.
Adittionally, I want all three images in the combined image to have the same height.
The code I am using is shown below:
% Create tiled layout
tiledlayout(1,3,'TileSpacing','tight','Padding','none');
% Image A
nexttile
ImageA = imread('image-a.png');
imshow(ImageA)
% Image B
nexttile
ImageB = imread('image-b.png');
imshow(ImageB)
% Image C
nexttile
ImageC = imread('image-c.png');
imshow(ImageC)
% Save combined image
exportgraphics(gcf,'image-combined.png')
With the following output:
Clearly, the spacing is not very tight, I would like it approximately 1/3 of the current amount.
It is also clear that the images all have different heights. Ideally, they would all have the same height, but retain their original aspect ratios.

Answers (2)

Matt J
Matt J on 11 Jul 2024 at 17:11
Edited: Matt J on 11 Jul 2024 at 17:21
One option would be to download subaxis, as an alternative to tiledlayout.
s=.01;
% Image A
subaxis(1,3,1,'SpacingHoriz',s)
ImageA = imread('image-a.png');
imshow(ImageA)
% Image B
subaxis(1,3,2,'SpacingHoriz',s)
ImageB = imread('image-b.png');
imshow(ImageB)
% Image C
subaxis(1,3,3,'SpacingHoriz',s)
ImageC = imread('image-c.png');
imshow(ImageC)

Matt J
Matt J on 11 Jul 2024 at 17:44
Edited: Matt J on 11 Jul 2024 at 19:10
You could also play with the tilespan:
% Create tiled layout
tiledlayout(1,305,'TileSpacing','none','Padding','none');
% Image A
nexttile(1,[1,100])
ImageA = imread('image-a.png');
imshow(ImageA)
% Image B
nexttile(103,[1,100])
ImageB = imread('image-b.png');
imshow(ImageB)
% Image C
nexttile(205,[1,100])
ImageC = imread('image-c.png');
imshow(ImageC)
  4 Comments
Daniel van Huyssteen
Daniel van Huyssteen on 12 Jul 2024 at 12:23
This does indeed force the images to all have the same dimensions.
What I am looking for is for the images to all have the same y-dimension, and the x-dimension would then be defined by the aspec ratio of the original images.
In this example the green figure should then be much wider than the other figures.
Matt J
Matt J on 12 Jul 2024 at 13:12
Edited: Matt J on 12 Jul 2024 at 13:12
You can still do that with imresize(). Set the OutputSize of each image to whatever you like.

Sign in to comment.

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!