调整轴大小以适合图像

时间:2017-03-11 21:14:59

标签: matlab matlab-figure matlab-guide

如何在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);

它的外观与它应该如何看起来

enter image description here

enter image description here

1 个答案:

答案 0 :(得分: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