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

25 次查看(过去 30 天)
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.

回答(2 个)

Matt J
Matt J 2024-7-11
编辑:Matt J 2024-7-11
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 2024-7-11
编辑:Matt J 2024-7-11
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 个评论
Daniel van Huyssteen
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 2024-7-12
编辑:Matt J 2024-7-12
You can still do that with imresize(). Set the OutputSize of each image to whatever you like.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by