How to change NaN values of a matrix to 1 drawing a polygon

1 次查看(过去 30 天)
how to use all the indixes inside the polygon h we draw with the following code to change NaN values of X matrix to 1.
load('quest.mat')
imagesc(f,ct,X)
h = drawpolygon('FaceAlpha',0);
xp=repelem(f,103,1);
yp=repmat(ct,256,1);
rpos=(f(2)-f(1))*floor(h.Position/ct(2)-ct(1))
in = inpolygon(xp,yp,rpos(:,1),rpos(:,2));
X(in)=1;

回答(1 个)

Image Analyst
Image Analyst 2021-11-21
Try it this way:
load('quest.mat')
subplot(2, 2, 1);
X(1) = 0;
imshow(X, []);
g = gcf;
g.WindowState = 'maximized';
uiwait(helpdlg('Draw a polygon. Double-click to finish it'))
h = drawpolygon('FaceAlpha',0);
xy = h.Position;
xp= xy(:, 1);
yp= xy(:, 2);
% rpos=(f(2)-f(1))*floor(h.Position/ct(2)-ct(1))
% in = inpolygon(xp,yp,rpos(:,1),rpos(:,2));
% X(in)=1;
[rows, columns] = size(X)
mask = poly2mask(xp, yp, rows, columns);
subplot(2, 2, 2);
imshow(mask)
X(mask) = 255;
subplot(2, 1, 2);
subplot(2, 2, 3);
imshow(X, []);

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by