RosettaCodeData/Task/Bitmap-Flood-fill/Mathematica/bitmap-flood-fill.math

10 lines
503 B
Text
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
createMask[img_, pos_, tol_] :=
RegionBinarize[img, Image[SparseArray[pos -> 1, ImageDimensions[img]]], tol];
floodFill[img_Image, pos_List, tol_Real, color_List] :=
ImageCompose[
SetAlphaChannel[ImageSubtract[img, createMask[img, pos, tol]], 1],
SetAlphaChannel[Image[ConstantArray[color, ImageDimensions[img]]],
Dilation[createMask[img, pos, tol],1]
]
]