2017-03-11 29 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

相关问题