6
$\begingroup$

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?

$\endgroup$
4
  • $\begingroup$ 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 $\endgroup$ Sep 25, 2015 at 14:54
  • $\begingroup$ Also see here: mathematica.stackexchange.com/questions/7781/… $\endgroup$ Sep 25, 2015 at 14:58
  • $\begingroup$ 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. $\endgroup$
    – mgm
    Sep 25, 2015 at 14:59
  • $\begingroup$ there you are, hopefully a better explanation of the binarization... $\endgroup$ Sep 25, 2015 at 15:10

2 Answers 2

7
$\begingroup$

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

$\endgroup$
2
$\begingroup$

Using RegionImage: (Introduced Sept 14, 2017)

RegionImage[Disk[]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.