フィルターのクリア

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

60 ビュー (過去 30 日間)
Daniel van Huyssteen
Daniel van Huyssteen 2024 年 7 月 11 日 15:49
編集済み: Matt J 2024 年 7 月 12 日 13:12
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 日 17:11
編集済み: Matt J 2024 年 7 月 11 日 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 2024 年 7 月 11 日 17:44
編集済み: Matt J 2024 年 7 月 11 日 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 件のコメント
Daniel van Huyssteen
Daniel van Huyssteen 2024 年 7 月 12 日 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 2024 年 7 月 12 日 13:12
編集済み: Matt J 2024 年 7 月 12 日 13:12
You can still do that with imresize(). Set the OutputSize of each image to whatever you like.

サインインしてコメントする。

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by