Effacer les filtres
Effacer les filtres

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

60 vues (au cours des 30 derniers jours)
Daniel van Huyssteen
Daniel van Huyssteen le 11 Juil 2024 à 15:49
Modifié(e) : Matt J le 12 Juil 2024 à 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.

Réponses (2)

Matt J
Matt J le 11 Juil 2024 à 17:11
Modifié(e) : Matt J le 11 Juil 2024 à 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 le 11 Juil 2024 à 17:44
Modifié(e) : Matt J le 11 Juil 2024 à 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 commentaires
Daniel van Huyssteen
Daniel van Huyssteen le 12 Juil 2024 à 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 le 12 Juil 2024 à 13:12
Modifié(e) : Matt J le 12 Juil 2024 à 13:12
You can still do that with imresize(). Set the OutputSize of each image to whatever you like.

Connectez-vous pour commenter.

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by