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

 채택된 답변

KSSV
KSSV 2019년 7월 9일
편집: KSSV 2019년 7월 9일

0 개 추천

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

추가 답변 (1개)

Rob Campbell
Rob Campbell 2021년 5월 30일

1 개 추천

I think you want the built-in function poly2mask

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품

릴리스

R2019a

태그

질문:

2019년 7월 9일

답변:

2021년 5월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by