View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.8 | 5 ratings Rate this file 18 Downloads (last 30 days) File Size: 6.18 KB File ID: #32112 Version: 1.5
image thumbnail



Nikolay S. (view profile)


07 Jul 2011 (Updated )

Finds a polygon enclosing the user defined mask. Inverse of poly2mask :).

| Watch this File

File Information

This functions goal is to find a polygon which enclosures a user supplied mask. It's a kind of a complementary of Matlab poly2mask function. The difference is that all contour points are returned- without missing points for linearly related points. In order to get a 100% complementary of poly2mask all points inside straight lines should be omitted. In my case I actually need all those points, as index of ROI.
Combining mask2poly with poly2mask the user can produce a mask from a contour (line with X and Y coordinates), and vise-versa.

MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
08 Sep 2016 Derya

Derya (view profile)

02 Aug 2014 ted p teng

ted p teng (view profile)

10 May 2013 Nikolay S.

Nikolay S. (view profile)

Hi Daniel.
Thanks for the comment. Unfortunately, it seems to be precise. Too bad I did not knew about the bwboundaries function, before writing my own. bwboundaries seems to works nicely. Out of curiosity can you send me an example of an image where my function fails (I've used it extensively in object tracking without problems)?

Comment only
09 May 2013 Daniel Golden

This is a great idea for a function, but it unfortunately fails in some cases. Matlab has a more robust method built in: bwboundaries.

10 Feb 2012 Lili

Lili (view profile)

13 Jul 2011 Daniel

Daniel (view profile)

Thanks for that contribution. The function works fine, is minimalistic and fast! Applied with a region growing algorithm to come to a final polygon.

13 Jul 2011 1.1

- "Inner" and "Outer" options replaced isIndex option
- Diff based edges calculation replaced contour based calculation for "Inner" and "Outer" options, which resulted in ~x3 shorter run time.

14 Jul 2011 1.2

An option to reorder the points so it will define a CW contour. Now you can plot the contours with line connecting the dots, without getting crazy lines all over the mask. Enable the "flagCW".

17 Jul 2011 1.3

Minor changes, according to Daniel's remarks.

25 Jul 2011 1.4

---------------2011-07-25----------- Ordering points according to rule of "nearest point" (accurate but slow) added.

25 Jul 2011 1.5

Minor change

Contact us