How to change NaN values of a matrix to 1 drawing a polygon
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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;
0 commentaires
Réponses (1)
Image Analyst
le 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, []);
0 commentaires
Voir également
Catégories
En savoir plus sur Elementary Polygons dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!