[英]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
該示例可以用作起點...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.