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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM