12
$\begingroup$

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["https://i.stack.imgur.com/oY9cp.jpg"]

photo

$\endgroup$
8
  • 5
    $\begingroup$ 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. $\endgroup$ Sep 11, 2013 at 15:00
  • 4
    $\begingroup$ If the finger tips are in the margins why not simply crop them out? $\endgroup$
    – s0rce
    Sep 11, 2013 at 15:48
  • 8
    $\begingroup$ Next time wear bright red gloves for easy post-processing...:) $\endgroup$
    – cormullion
    Sep 11, 2013 at 16:03
  • 2
    $\begingroup$ @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. $\endgroup$
    – rm -rf
    Sep 11, 2013 at 17:40
  • 6
    $\begingroup$ 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) $\endgroup$
    – Mr.Wizard
    Sep 11, 2013 at 19:39

2 Answers 2

22
$\begingroup$

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

img = Import["https://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.

$\endgroup$
2
  • $\begingroup$ Very nice! is there a way without using "magic" numbers (like 0.67)? $\endgroup$ Sep 12, 2013 at 5:12
  • $\begingroup$ @belisarius -- the procedure isn't terribly sensitive to the threshold value, but of course this may vary depending on the image. $\endgroup$
    – bill s
    Sep 12, 2013 at 14:59
13
$\begingroup$

This may help:

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

Mathematica graphics

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

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Interesting this Inpaintfunction. $\endgroup$
    – Murta
    Sep 11, 2013 at 22:12
  • $\begingroup$ @Murta The TotalVariationand NavierStokes methods are very beautiful $\endgroup$ Sep 12, 2013 at 0:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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