2013-06-25 40 views
0
clear all; close all; clc; 
A = im2double(imread('cameraman.jpg')); 
figure(1) 
imshow(A) 

C = chunking(A,400,400) % separates picture; 
[m n] = size(C); 
k = 1; 
figure(1) 
for i = 1:m 
    for j = 1:n 
     subplot(m,n,k) 
     imshow(C{i,j}) 
     axis off; 
     k = k + 1; 

    end 
end 

所以在上面的代碼,我嘗試將圖片分割成400×400像素塊。由於圖像不是400x400的倍數,所以在邊框和右下角會有不等的部分(仍然是方形圖像)。但是,當我使用子圖時,它會將最後一個塊的大小調整爲相同大小。我試圖獲得出場周圍,設置位置,但它給出了寬度和高度爲每個插曲是一樣的嗎?![在這裏輸入的形象描述] [1]如何設置的多個畫面的次要情節線在Matlab

http://imgur.com/2VUYZr1

回答

0

要調整,如果軸你有不到400個像素來顯示。您應該將句柄存儲到每個子圖中,然後在需要縮小時調整其大小。

您對次要情節的呼叫應該是這樣的:

h = subplot(m,n,k); 
num_rows = size(C{i,j}, 1); 
num_cols = size(C{i,j}, 2); 
set(h, 'units', 'pixels') 
old_axes_pos = get(h, 'position'); 
new_axes_pos = old_axes_pos; 
if num_cols < 400 
    new_axes_pos(3) = num_cols; % Make this axes narrower 
end 
% If the figure cannot be full height 
if num_rows < 400 
    new_axes_pos(4) = num_rows; % Make this axes shorter 
    new_axes_pos(2) = old_axes_pos(2) + (400 - num_rows); % Move the bottom up 
end 
set(h, 'position', new_axes_pos) % Change the size of the figure