简体   繁体   English

在图像上方创建网格

[英]Create a grid over an image

I want to create a grid over an image on matlab. 我想在Matlab上的图像上方创建网格。 At the same time, I want the image to be clickable and color the box of the grid I clicked. 同时,我希望图像可以单击并为我单击的网格的颜色上色。

Can anyone give me some guidance for this? 谁能给我一些指导吗? What functions to use? 使用什么功能?

You may use the following example: 您可以使用以下示例:

%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

在此处输入图片说明

The example may be used as a starting point... 该示例可以用作起点...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM