Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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;

Risposte (1)

Image Analyst
Image Analyst il 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, []);

Categorie

Scopri di più su Elementary Polygons in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by