I have a rasterized image img
that is created by this code:
img =
Image @
Graphics[
{Disk[], Disk[{4, 4}, 1.5], Disk[{-4, 5}, 2], Disk[{0, -6}, 4]},
PlotRange -> 11]
I want to color the circles depending on their size (near white for the biggest, going through darker grays until the smallest gets colored black, or something similar).
I know it has something to do with MorphologicalComponents
, but I don't know how to colorize the different components.
EDIT:
Actually the input image was not the circle one, it was this:
And when I run your code, even though the points image gets good results, this one gives some error. The output is this:
Which doesn't recognize the areas of any squares.
Colorize[m=MorphologicalComponents[ColorNegate@Binarize@img], ColorRules -> Join[{0 -> White}, Thread[SortBy[ComponentMeasurements[m, "FilledCount"], Last][[All, 1]] -> GrayLevel /@ {.1, .6, .8, .9}]]]
- fiddle with values to taste... $\endgroup$