Convert mask to region-of-interest polygons


Updated 30 Jun 2015

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 (
mask = imread('circuit.tif')>100;
P = mask2poly(mask);
axis on; box off; grid on;
hold on;
for n = 1:numel(P)
if P(n).IsFilled
color = 'w';
color = 'y';
hold off;

Cite As

Kesh Ikuma (2023). mask2poly(mask) (, MATLAB Central File Exchange. Retrieved .

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!
Version Published Release Notes

* Rewritten the code handling the mask edges that terminate at the mask boundary. A bug in previous version resulted in an infinite loop.
* Fixed the bug that caused a erroneous ROI polygon from a one-pixel wide mask

Bug fixes:
- fixed error when mask covers the entire area (caused by missing IsFilled field)
- fixed the bug in the algorithm to determine IsFilled output

bug fix

fixed missing IsFilled field if mask contains no ROI

Added example to the description