6

Let's suppose I have something like this (the image resulting from this):

ColorNegate[Rasterize[Graphics[Circle[{100, 100}, 50]]]]

Now, what I want to do is fill the inside of the circle (in the image, not transforming Circle->Disk :) ) with White (the color of the circle).

Ideas?

mgm
  • 1,029
  • 7
  • 15
  • Binarize@FillingTransform@ ColorNegate[Rasterize[Graphics[Circle[{100, 100}, 50]]]] works for your specific case, though without the binarize the color is different to the edge – dr.blochwave Sep 25 '15 at 14:54
  • Also see here: http://mathematica.stackexchange.com/questions/7781/how-to-fill-in-an-irregular-border-of-an-image – dr.blochwave Sep 25 '15 at 14:58
  • Oh... Of course it's FillingTransform. I didn't know about the Binarize. Thank you. If you want to create an answer, and explain maybe better the Binarize part, I'll accept it. – mgm Sep 25 '15 at 14:59
  • there you are, hopefully a better explanation of the binarization... – dr.blochwave Sep 25 '15 at 15:10

2 Answers2

7

FillingTransform is what you're after:

img = FillingTransform@ColorNegate[Rasterize[Graphics[Circle[{100, 100}, 50]]]]

enter image description here

But this gives a gray fill because your image wasn't binary to begin with. Easy to fix, e.g. with a subsequent Binarize:

Binarize@img

enter image description here

Alternatively, ColorReplace[] might provide a more general solution.

ColorReplace[img, Gray -> White]

enter image description here

dr.blochwave
  • 8,768
  • 3
  • 42
  • 76
2

Using RegionImage: (Introduced Sept 14, 2017)

RegionImage[Disk[]]

enter image description here

Syed
  • 52,495
  • 4
  • 30
  • 85