Borrar filtros
Borrar filtros

How to convert a closed curve into a binary mask

7 visualizaciones (últimos 30 días)
Maura E. Monville
Maura E. Monville el 9 de Jul. de 2019
Respondida: Rob Campbell el 30 de Mayo de 2021
I have a set of 2D closed curves represented by their X and Y ordered coordinates in a text file.
I have attached one of the curves as an example.
My goal is to convert the enclosed area into a binary image.
Builtin dunction "poly2mask" generates a completely black square whereas I would like the region inside the closed curve to be black
and the region outside the curve to be white.
Thank you in advance for any suggestion and help.
Regards,
Maura

Respuesta aceptada

KSSV
KSSV el 9 de Jul. de 2019
Editada: KSSV el 9 de Jul. de 2019
data = importdata('data.txt') ;
x = data(:,1) ;
y = data(:,2) ;
N = 500 ;
xi = linspace(min(x),max(x),N) ;
yi = linspace(min(y),max(y),N) ;
[X,Y] = meshgrid(xi,yi) ;
idx = inpolygon(X,Y,x,y) ;
Z = ones(size(X)) ;
Z(idx) = 0 ;
imshow(Z)
untitled.bmp

Más respuestas (1)

Rob Campbell
Rob Campbell el 30 de Mayo de 2021
I think you want the built-in function poly2mask

Categorías

Más información sobre Graphics Object Identification en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by