File Exchange

image thumbnail

mask2poly(mask)

version 1.2.2.0 (9.06 KB) by Kesh Ikuma
Convert mask to region-of-interest polygons

9 Downloads

Updated 30 Jun 2015

View Version History

View License

P = MASK2POLY(BW) reverses the POLY2MASK function in Image Processing Toolbox. It takes a binary image BW and returns an array of struct, P. Each element of P defines either a polygon or a hole within a polygon.
This function requires another FEX function: contourcs (http://www.mathworks.com/matlabcentral/fileexchange/28447)
Example:
mask = imread('circuit.tif')>100;
P = mask2poly(mask);
figure;
imagesc(mask);
axis on; box off; grid on;
hold on;
for n = 1:numel(P)
if P(n).IsFilled
color = 'w';
else
color = 'y';
end
plot(P(n).X,P(n).Y,color);
end
hold off;

Cite As

Kesh Ikuma (2020). mask2poly(mask) (https://www.mathworks.com/matlabcentral/fileexchange/45980-mask2poly-mask), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

Jaroslaw Tuszynski

Works great for me, once I changed line 51 to P(:).IsFilled = [];

Kyle Savidge

Try the following instead of line 53:

numCountours = numel(P);
if numCountours
P(numCountours).IsFilled = [];
else
return
end

BL

receiving the following error:

Error in mask2poly (line 53)
P().IsFilled = [];

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!