2017-03-11 101 views
1

如何在matlab GUI上調整我的座標軸大小以適應剛剛調整大小的圖像大小?調整軸的大小以適合圖像

我有這樣的:

I = imread('honolulu.png'); 

I = imresize(im2double(I), [600, 700]); 

我畫上的圖片網格之後,但由於軸大小不同的網格不好看。但是,如果我創建一個圖形,然後在GUI外面的圖形上完成它,它看起來很完美。 全碼:

%Load map 

I = imread('honolulu.png'); 

%Resize image to be multiple of 50 in each axis. 
I = imresize(im2double(I), [600, 700]); 

%Draw grid of 50x50 pixels. 
I(50:50:end, :, :) = 255; 
I(:, 50:50:end, :) = 255; 
axes(handles.axes1); 
h = handles.axes1;imshow(I); 

while (ishandle(h)) 
    try 
     [x, y] = ginput(1); 
    catch me 
     %break loop in case image is closed. 
     break; 
    end 

    %Compute top left coordinate of block clicked. 
    x0 = floor((x-1)/50)*50; 
    y0 = floor((y-1)/50)*50; 

    %Set block RGB to random color. 
    I(y0+1:y0+50-1, x0+1:x0+50-1, 1) = rand(); 
    I(y0+1:y0+50-1, x0+1:x0+50-1, 2) = rand(); 
    I(y0+1:y0+50-1, x0+1:x0+50-1, 3) = rand(); 

    imshow(I); 
end 
% Choose default command line output for city_planning 
handles.output = hObject; 

% Update handles structure 
guidata(hObject, handles); 

它的外觀VS它應該是怎樣看

enter image description here

enter image description here

+0

你能更具體嗎?你如何繪製網格?示例圖像會很有幫助。 – ConfusinglyCuriousTheThird

+0

@ConfusinglyCuriousTheThird更新 – carlosremove

回答

0

該行正在消失的繪圖窗口改變大小 - 一個走樣的東西/渲染問題,我猜。在其他地方,其他人沒有很好的答案就提出了類似的問題。

我發現的最好的辦法是將初始放大倍率設置爲100%,然後防止調整大小。這裏有一個類似的例子:

close all; 
clear all; 
clc; 

I = imread('peppers.png'); 
I = imresize(im2double(I), [600, 700]); 

%Draw grid of 50x50 pixels. 
I(50:50:end, :, :) = 1; 
I(:, 50:50:end, :) = 1; 


h = imshow(I,'initialMagnification',100); 
set(gcf,'Resize','off') 

%% 
while (ishandle(h)) 
    try 
     [x, y] = ginput(1); 
    catch me 
     %break loop in case image is closed. 
     break; 
    end 

    %Compute top left coordinate of block clicked. 
    x0 = floor((x-1)/50)*50; 
    y0 = floor((y-1)/50)*50; 

    %Set block RGB to random color. 
    I(y0+1:y0+50-1, x0+1:x0+50-1, 1) = rand(); 
    I(y0+1:y0+50-1, x0+1:x0+50-1, 2) = rand(); 
    I(y0+1:y0+50-1, x0+1:x0+50-1, 3) = rand(); 

    h = imshow(I); 
end 
+0

答案的作品。但是,當我出於某種原因關閉窗口時,出現錯誤,使用guidata(行87) H必須是數字或數字後代的句柄。 – carlosremove

+0

現在試試吧,我認爲它應該可以工作。 – ConfusinglyCuriousTheThird

+0

你用while循環實現的條件/行爲是什麼? – ConfusinglyCuriousTheThird

相關問題