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 scripts in my GitHub repository, which includes the classic image of Lena to use it in the demo. I suggest play with it in order to understand how it works. The scripts include plenty of comments in which I tried to explain each of the steps as clear as possible.


If you have any questions, comments, or feedback, please open a discussion. If there is a problem with the code (e.g., mistake), please open an issue. You can always drop me a line on Twitter (@amoncadatorres). Lastly, if you found this useful, fun, or just want to show your appreciation, you can always buy me a cookie. Cheers!