How to convert a closed curve into a binary mask
11 ビュー (過去 30 日間)
Maura E. Monville 2019 年 7 月 9 日
回答済み: Rob Campbell 2021 年 5 月 30 日
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.
KSSV 2019 年 7 月 9 日
編集済み: KSSV 2019 年 7 月 9 日
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 ;
その他の回答 (1 件)
Rob Campbell 2021 年 5 月 30 日
Find more on Region and Image Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!