Color fill, the ability to apply a desired color to an enclosed area, is one of the basic functions provided by most graphic applications. Is there a similar function provided in Mathematica? For example, how to obtain a red, green, blue and yellow horses silhouette from the picture below in Mathematica?

im = Import["http://i.stack.imgur.com/ZDeYq.jpg"]
ReplacePixelValue[im, {924, 221} -> Blue]

ReplacePixelValue seems only work on one pixel only.

Colorize seems provide no controls on obtaining a specific color.

ColorReplace seems only work on a bundle of the same color all together .

enter image description here

im = Binarize@Import["http://i.stack.imgur.com/ZDeYq.jpg"];
          ColorRules -> {1 -> Red, 2 -> Yellow, 3 -> Blue, 4 -> Green}]

Mathematica graphics

  • $\begingroup$ Thank you so much. It seems there is a strange behaviour behind MorphologicalComponents, So I raised another question about it. $\endgroup$ – Putterboy Sep 11 '14 at 7:57
  • $\begingroup$ Is this method only good for binarized pictures? $\endgroup$ – Putterboy Sep 11 '14 at 10:30
  • $\begingroup$ @Putterboy Not at all: MorphologicalComponents[image,t] treats values above t as foreground. $\endgroup$ – Dr. belisarius Sep 12 '14 at 19:16

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.