调整轴大小以适合图像

Resize axes to fit image

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

外观与应有的外观

随着情节 window 大小的变化,线条正在消失 - 我猜这是一个 aliasing/rendering 问题。在其他地方,其他人也问过类似的问题,但没有很好的答案。

我发现的最好的方法是将初始放大倍率设置为 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