# How to color separate a colored-in-pencil drawing?

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 https://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 https://mathematica.stackexchange.com/a/5407/10 )

EDIT2: I see https://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).

• Have you tried rubbing some lembas over the drawings? 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. 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. 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. Jun 26 '14 at 5:27
• This might be useful for identifying the pencil colour. Jun 26 '14 at 10:29

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"];

girl = Import["http://imgur.com/Q5ReXSX.jpg"];