在图像上创建网格

Create a grid over an image

我想在 matlab 上的图像上创建一个网格。同时,我希望图像可以点击,并为我点击的网格框着色。

任何人都可以给我一些指导吗?使用什么功能?

您可以使用以下示例:

%Load sample image.
I = imread('yellowlily.jpg');

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

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

h = figure;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

该示例可用作起点...