Create figures with different number of images but same sizes
Afficher commentaires plus anciens
I try to create 2 figures in 2 different scripts.
Script 1 looks like this:
img_sos = rand(64);
img_oar_pixel = rand(64);
img_oar_block = rand(64);
img_sos = img_sos / max(img_sos(:));
img_oar_pixel = img_oar_pixel / max(img_oar_pixel(:));
img_oar_block = img_oar_block / max(img_oar_block(:));
f = figure;
tl = tiledlayout(1, 3, 'TileSpacing', 'compact', 'Padding', 'compact');
clim1 = [0 1];
cmap1 = jet;
ax1 = [];
ax1(1) = nexttile;
imagesc(img_sos, clim1);
axis image off;
title('Sum-of-Squares', 'FontSize', 10);
ax1(2) = nexttile;
imagesc(img_oar_pixel, clim1);
axis image off;
title('Adaptive Kombination (Pixelweise)', 'FontSize', 10);
ax1(3) = nexttile;
imagesc(img_oar_block, clim1);
axis image off;
title('Adaptive Kombination (Blockweise)', 'FontSize', 10);
set(ax1, 'Colormap', cmap1);
cb1 = colorbar(ax1(end), 'eastoutside');
cb1.Label.String = 'Normierte Signalintensität';
cb1.Label.FontSize = 10;
cb1.Ticks = 0:0.2:1;
My second script looks like this:
figure; %<---Matt J added
img_oar_rec = rand(64);
img_oar_rec = img_oar_rec/max(img_oar_rec(:));
img_mask = rand(64);
tiledlayout(1, 2, 'TileSpacing', 'compact', 'Padding', 'compact');
ax1 = nexttile;
imagesc(img_oar_rec, [0 1]);
axis image off;
colormap(ax1, 'jet');
cb = colorbar;
cb.Label.String = 'Normierte Signalintensität';
cb.Label.FontSize = 10;
title('Adaptive Kombination', 'FontSize', 10);
ax2 = nexttile;
imagesc(img_mask);
axis image off;
colormap(ax2, 'gray');
title('Binäre Maske', 'FontSize', 10);
As I want to use these figures in a latex report, I want to save these figures as jpg.
But in both figures, the images should have the same size. Same for the titles and colorbar strings.
How can I do that? I should not scale figures in latex.
1 commentaire
Réponses (1)
If you mean you want a common image size across all axes in both figures, I think the best that you can do is relocate both layouts to a common master figure. The relocation can be done automatically, as below.
You can then make cropped copies of the master figure in MSWord or PowerPoint to achieve separate figures.
%% Create initial figures
tl1=fig1();
tl2=fig2();
%% Relocate to master figure
figure('Position',[ 34 137 1245 813]);
ax=[flip(tl1.Children);flip(tl2.Children)];
ax=findobj(ax,'Type','axes');
TL=tiledlayout(2,3,'TileSpacing', 'compact', 'Padding', 'compact');
for i=1:numel(ax)
ax(i).Parent=TL;
ax(i).Layout.Tile=i;
end
close([tl1.Parent,tl2.Parent])
function tl=fig1()
img_sos = rand(64);
img_oar_pixel = rand(64);
img_oar_block = rand(64);
img_sos = img_sos / max(img_sos(:));
img_oar_pixel = img_oar_pixel / max(img_oar_pixel(:));
img_oar_block = img_oar_block / max(img_oar_block(:));
f = figure;
tl = tiledlayout(1, 3, 'TileSpacing', 'compact', 'Padding', 'compact');
clim1 = [0 1];
cmap1 = jet;
ax1 = [];
ax1(1) = nexttile;
imagesc(img_sos, clim1);
axis image off;
title('Sum-of-Squares', 'FontSize', 10);
ax1(2) = nexttile;
imagesc(img_oar_pixel, clim1);
axis image off;
title({'Adaptive Kombination';'(Pixelweise)'}, 'FontSize', 10);
ax1(3) = nexttile;
imagesc(img_oar_block, clim1);
axis image off;
title({'Adaptive Kombination';'(Blockweise)'}, 'FontSize', 10);
set(ax1, 'Colormap', cmap1);
cb1 = colorbar(ax1(end), 'eastoutside');
cb1.Label.String = 'Normierte Signalintensität';
cb1.Label.FontSize = 10;
cb1.Ticks = 0:0.2:1;
end
function tl=fig2()
figure; %<---Matt J added
img_oar_rec = rand(64);
img_oar_rec = img_oar_rec/max(img_oar_rec(:));
img_mask = rand(64);
tl=tiledlayout(1, 2, 'TileSpacing', 'compact', 'Padding', 'compact');
ax1 = nexttile;
imagesc(img_oar_rec, [0 1]);
axis image off;
colormap(ax1, 'jet');
cb = colorbar;
cb.Label.String = 'Normierte Signalintensität';
cb.Label.FontSize = 10;
title('Adaptive Kombination', 'FontSize', 10);
ax2 = nexttile;
imagesc(img_mask);
axis image off;
colormap(ax2, 'gray');
title('Binäre Maske', 'FontSize', 10);
end
4 commentaires
dpb
le 13 Juil 2025
"... I think the best that you can do is relocate both layouts to a common master figure. "
Couldn't you achieve the same effect in two figures by using the 1,3 layout for each figure so wouldn't have to edit later separtely?
OP's original first has an issue in that the titles are in too large a font for the available room and overlap...either have to cut down the font or shorten the title or wrap text or...
Matt J
le 13 Juil 2025
I don't think so. tiledlayout has strange, opaque rules for determining axis sizes. They would be difficult to sync across separate figures.
dpb
le 14 Juil 2025
Differences probably come from the size of label fields; perhaps if controlled the format to be consistent across all...
Matt J
le 14 Juil 2025
Go for it, but I think it'll be more trouble than it's worth.
Catégories
En savoir plus sur Image Processing Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


