# How could I use Mathematica to remove finger tips that appear in images?

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


-
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

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


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.

-
+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

This may help:

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


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


-
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