Creating image masks interactively

Take a look at the following example in documentation: Use a marker to specify the holes to be filled

How to make such mask quickly and interactively?

I post here a function that allows to do that.

MakeMask[i_] := 
 Manipulate[
  Row[{Show[i, PlotRange -> Thread[{{1, 1}, ImageDimensions[i]}]], 
    mask = Image[
      Reverse@Transpose@
        SparseArray[# -> 1 & /@ Round[p], ImageDimensions[i]], 
      ImageSize -> ImageDimensions[i]]}],
  Button["pasre mask", Print[mask]],
  {{p, {ImageDimensions[i]/2}}, Locator, LocatorAutoCreate -> True, 
   Appearance -> Style["+", Red, 40]}, {mask, ControlType -> None}]

7155makemask234.gif

6 Likes