MATLAB: Switch mask values to outside ROI to 1 and inside to 0

imageimage processingImage Processing Toolboximfreehandmaskregions of interestroi

In a jist, I am writing a code that allows for freehand drawing of an ROI in an image. However, I want to use this ROI as unique sort of mask… within the ROI has to have values of 0 and outside 1. Is there a quick way of doing so? Like perhaps just changing the 1's to 0's and vice versa?

Best Answer

Yes, use tilde:
mask = ~mask;
I attach imfreehand examples.