Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'd like to pick out just the "pencil" color in some drawings done by a young member of the household (he'd like to print out copies of these pictures and distribute them to his class mates on the last day of school, but has already colored them).

I tried Binarize, which allows me to craft a color selection function, picking levels of each of Red, Green, or Blue. For example:

Clear[ girl, boy ] ;
boy = Import[ "http://imgur.com/mRRhOgo.jpg" ]
girl = Import[ "http://imgur.com/Q5ReXSX.jpg" ]
Binarize[ girl, #[[1]] > 0.8 & ]
Binarize[ girl, #[[2]] > 0.8 & ]
Binarize[ girl, #[[3]] > 0.8 & ]

The last works fairly well, but happens to leave a really dark section by the red belt. I figure it should be possible to code a color selection function that picks only things in the range of the gray pencil colored text, but I'd have to figure out what that color is first, and am not sure of a good approach to do that (other than sampling specific pixel values).

I'd imagine this problem could be solved by sorting the image points by color and picking the dominant ones. Then find the "gray colors" or ranges of those grays, and finally coding an image function selection for binarize to pick that color or range of colors. However, it's not clear to me exactly how to go about doing that.

EDIT: It looks like http://mathematica.stackexchange.com/a/5415/10 provides reasonable looking instructions on how to pick out just one color, so the problem may be reduced to just finding that "pencil" color. I've tried the Manipulate sliders in some of the other answers for that question, but find them very slow to update ( especially that of http://mathematica.stackexchange.com/a/5407/10 )

EDIT2: I see http://mathematica.stackexchange.com/a/4795/10 provides a locator based way of picking a color, which can probably be used to solve the find the "pencil" color part of the problem (although I'm still not sure how various darknesses of the pencil lines would be dealt with).

share|improve this question
Have you tried rubbing some lembas over the drawings? –  belisarius Jun 26 '14 at 3:12
There is an old question on this site (from near the beginning) about reading text on an obscured page; I think some answers there might be useful here. I cannot find it. Once again I request the help of the community to find it. –  Mr.Wizard Jun 26 '14 at 5:14
Many years ago I worked on something like this but sadly the memory has almost faded away. I do remember that there was an algorithm to decompose an image into arbitrary color channels, and I think that would be perfect here as each pencil color would have its own channel. I hope this sounds familiar to someone with more recent image processing experience. –  Mr.Wizard Jun 26 '14 at 5:22
I think this algorithm has been added to Mathematica after version 7: "ColorSeparate[image, {c1, c2, ...}] extracts the specified color components." Please, someone try this; if it works as I anticipate and it is given the proper primaries the result should be very good. –  Mr.Wizard Jun 26 '14 at 5:27
This might be useful for identifying the pencil colour. –  Simon Woods Jun 26 '14 at 10:29

2 Answers 2

You can get a reasonable result by converting to HSB space and removing the hue channel (ColorSeparate then use ImageAdd to recombine the saturation and brightness), followed by an adjustment to the contrast and gamma (play around with the values to get something you like):

image = Import["http://imgur.com/mRRhOgo.jpg"];
pencil = ImageAdd @@ Rest @ ColorSeparate[image ~ColorConvert~ "HSB"];
ImageAdjust[pencil, {2, 0, 3}]

enter image description here

enter image description here

share|improve this answer

This separates out the color from the black and white, and then subtracts the two. The final step of binarization returns it to (mostly) a line drawing.

girl = Import["http://imgur.com/Q5ReXSX.jpg"];
girlP = ColorNegate@
   ImageAdjust@ImageDifference[girl, (ColorSeparate@girl)[[3]]];
girl2 = ColorNegate@ImageAdjust@ImageSubtract[girlP, girl];
Binarize[(ColorSeparate@girl2)[[1]], 0.7]

enter image description here

(No lembas bread required).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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