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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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