Borrar filtros
Borrar filtros

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

60 visualizaciones (últimos 30 días)
Daniel van Huyssteen
Daniel van Huyssteen el 11 de Jul. de 2024 a las 15:49
Editada: Matt J el 12 de Jul. de 2024 a las 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.

Respuestas (2)

Matt J
Matt J el 11 de Jul. de 2024 a las 17:11
Editada: Matt J el 11 de Jul. de 2024 a las 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 el 11 de Jul. de 2024 a las 17:44
Editada: Matt J el 11 de Jul. de 2024 a las 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 comentarios
Daniel van Huyssteen
Daniel van Huyssteen el 12 de Jul. de 2024 a las 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 el 12 de Jul. de 2024 a las 13:12
Editada: Matt J el 12 de Jul. de 2024 a las 13:12
You can still do that with imresize(). Set the OutputSize of each image to whatever you like.

Iniciar sesión para comentar.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by