matlab subplot(figure)如何设置使得图像最终显示出来不一样大小

1. 问题描述

figure
subplot(1, 2, 1), imshow(A)
subplot(1, 2, 2), imshow(B)

无论 A 和 B 的 size 是否一致,最终显示出来的 figure 中的两幅图像大小都是相同的。

2. 原因及解决

之所以第二个图看起来和第一张图等大,是因为第二个 subplot 的 XY 轴的单位长度比第一个subplot中的要长(二者的比例尺不同)。所以简单一点的解决方法是:将第二个 subplot 的 XLim 和 YLim 属性设为和第一个 subplot 中的对应属性值。

3. demo:图像金字塔变换

% 加载图像数据到内存
I = imread('cameraman.tif');
size(I)

% reduce ==> {2, 4, 8}
I1 = impyramid(I, 'reduce'); size(I1)
I2 = impyramid(I1, 'reduce'); size(I2)
I3 = impyramid(I2, 'reduce'); size(I3)

figure
a1 = subplot(1, 4, 1); imshow(I),  
xs = get(a1, 'xlim'); ys = get(a1, 'ylim');
a2 = subplot(1, 4, 2); imshow(I1),
set(a2, 'xlim', xs, 'ylim', ys);
a3 = subplot(1, 4, 3); imshow(I2),
set(a3, 'xlim', xs, 'ylim', ys);
a4 = subplot(1, 4, 4); imshow(I3)
set(a4, 'xlim', xs, 'ylim', ys);

I1 = impyramid(I, 'expand'); size(I1)
I2 = impyramid(I1, 'expand'); size(I2)
I3 = impyramid(I2, 'expand'); size(I3)

figure
a1 = subplot(1, 4, 1); imshow(I3),  
xs = get(a1, 'xlim'); ys = get(a1, 'ylim');
a2 = subplot(1, 4, 2); imshow(I2),
set(a2, 'xlim', xs, 'ylim', ys);
a3 = subplot(1, 4, 3); imshow(I1),
set(a3, 'xlim', xs, 'ylim', ys);
a4 = subplot(1, 4, 4); imshow(I)
set(a4, 'xlim', xs, 'ylim', ys);
原文地址:https://www.cnblogs.com/mtcnn/p/9421365.html