Alex Rivera | Logout

What processing steps should I use to clean photos of line drawings?

Asked 2011-01-08T03:31:19.803
14

My usual method of 100% contrast and some brightness adjusting to tweak the cutoff point usually works reasonably well to clean up photos of small sub-circuits or equations for posting on E&R.SE, however sometimes it's not quite that great, like with this image:

alt text

What other methods besides contrast (or instead of) can I use to give me a more consistent output?

I'm expecting a fairly general answer, but I'll probably implement it in a script (that I can just dump files into) using ImageMagick and/or PIL (Python) so if you have anything specific to them it would be welcome.

Ideally a better source image would be nice, but I occasionally use this on other folk's images to add some polish.

Edit
Report

1 Answer

19

One common way to remove the different background illumination is to calculate a "white image" from the image, by opening the image.

In this sample Octave code, I've used the blue channel of the image, because the lines in the background are least prominent in this channel (EDITED: using a circular structuring element produces less visual artifacts than a simple box):

src = imread('lines.png');
blue = src(:,:,3);
mask = fspecial("disk",10);
opened = imerode(imdilate(blue,mask),mask);

Result: opened

Then subtract this from the source image:

background_subtracted = opened-blue;

background_subtracted (contrast enhanced version)

Finally, I'd just binarize the image with a fixed threshold:

binary = background_subtracted < 35;

binary

answered 2011-01-08T12:39:20.893

Your Answer