How to change NaN values of a matrix to 1 drawing a polygon
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Image Analyst
el 21 de Nov. de 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 comentarios
Ver también
Categorías
Más información sobre Elementary Polygons en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!