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

3 Ansichten (letzte 30 Tage)
Felipe Rincón
Felipe Rincón am 21 Nov. 2021
Beantwortet: Image Analyst am 21 Nov. 2021
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;

Antworten (1)

Image Analyst
Image Analyst am 21 Nov. 2021
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, []);

Kategorien

Mehr zu Elementary Polygons finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by