I have a png with the outline of an irregularly shaped object which I want to turn into a mask. I need to floodfill the interior with black, and then swap black and white. It's 8-bit grayscale, with values of 0 and 255 only.
I can't fill the exterior, leaving the interior white, since the outline itself must be included in the positive area. (Assume the array values for black, white, and red are already defined.)
mask = Vips::Image.new_from_file(fl)
mask = mask.draw_flood(black, center_x, center_y, :equal => true) * -1
This returns an all-black raster. Boo hoo! This works, but is ugly and inefficient.
mask = mask.draw_flood(black, center_x, center_y, :equal => true)
mask = mask.draw_flood(red, 0, 0, :equal => true)
mask = mask.draw_flood(white, center_x, center_y, :equal => true)
mask = mask.draw_flood(black, 0, 0, :equal => true)
Does anyone know a more elegant solution? Thanks for any guidance.