Generating a Binary Mask

When working with images, selecting a specific region of an image to work with is quite common. Therefore I made a script that allows you to generate a mask with one or more regions of interest (ROIs). The shape of the ROIs can be rectangular, elliptic, (irregular) polygon, or free-hand drawn.

Original Lena, generated mask, and masked Lena.

You can find the script in MATLAB’s File Exchange. The submission includes a demo, which I suggest you try in order to understand how it works. The script includes plenty of comments in which I tried to explain as clear as possible each of the steps. If you still have questions about it or, even better, suggestions for its improvement, please leave a comment either here or in the submission’s page.