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 used my photo camera to "scan" a heavy dictionary. I tried to have flat images by pressing the margins of the pages with my fingers.

The color of the background is (normally) black and my fingers have different colors from the color of the page margins.

My questions is: Is it possible to apply Mathematica photo tools to automatically remove the finger tips from the scanned pages?

For experiments, you can freely use the following photo

img = Import["http://i.stack.imgur.com/oY9cp.jpg"]


share|improve this question
It's a good idea to show what what you have done so far, and where you have got stuck, otherwise it looks like you're simply asking other people to write your code for you. –  Simon Woods Sep 11 '13 at 15:00
If the finger tips are in the margins why not simply crop them out? –  s0rce Sep 11 '13 at 15:48
Next time wear bright red gloves for easy post-processing...:) –  cormullion Sep 11 '13 at 16:03
@kornaros Why do you need to refill the margins? You can easily find out the bounding box of the textual matter on each page and crop everything else. Then, use a Hough transform (use ImageLines) to find the orientation of the text and correct it to make all the pages horizontal. Then you can whiten the background and re-pad the margins to your desired thickness. –  rm -rf Sep 11 '13 at 17:40
I found the title of this question, less the last three words that wrapped to the next line, quite disturbing. We don't support automated torture at Mathematica. :o) –  Mr.Wizard Sep 11 '13 at 19:39
show 3 more comments

2 Answers

Here's a way to approach fingertip removal using some of the morphological operations:

img = Import["http://i.stack.imgur.com/oY9cp.jpg"];
blurImg = ImageAdjust[ImageConvolve[img, ConstantArray[0.01, {100, 100}]]];
bw = Erosion[MorphologicalBinarize[blurImg, 0.67], 50];
boundBox = MorphologicalComponents[bw, Method -> "BoundingBox"];
mask = Erosion[Image[boundBox], 130];
ImageAdjust[ImageMultiply[img, mask]]

enter image description here

The first step in the processing blurs the image (a 100x100 filter kernel is used). This is then binarized and eroded to give a black and white image that roughly includes the text area. The MorphologicalComponents command makes this a rectangular bounding box, which is then eroded to remove the fingertips. The final step multiplies the eroded bounding box with the original image.

share|improve this answer
+1. This is impressive work. –  RunnyKine Sep 12 '13 at 3:57
Very nice! is there a way without using "magic" numbers (like 0.67)? –  belisarius Sep 12 '13 at 5:12
@belisarius -- the procedure isn't terribly sensitive to the threshold value, but of course this may vary depending on the image. –  bill s Sep 12 '13 at 14:59
add comment

This may help:

i = Import["http://i.stack.imgur.com/z9s3p.png"]

Mathematica graphics

m = Dilation[Binarize[ColorSeparate[i, "HSB"][[2]]], 3]
i1 = Inpaint[i, m, Method -> {"TextureSynthesis"}]

Mathematica graphics

share|improve this answer
Interesting this Inpaintfunction. –  Murta Sep 11 '13 at 22:12
@Murta The TotalVariationand NavierStokes methods are very beautiful –  belisarius Sep 12 '13 at 0:05
add comment

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.