Page 1 of 1

Extract Page from Scanned Image

Posted: 2015-09-22T20:20:24-07:00
by gvandyk
Hi

How can I extract a page from a scanned image that was taken with a camera?

I want to extract the the page that is displayed within the below image. I did manage to extract most of the page using "autotrim", but I am still left with the piece of the "left" page on the opposite glass.

How can I detect the page borders. I managed to get a rough outline with "-edge" and "-canny", but is still left with the outlines of the words as well.

Any help would be appreciated.

https://www.dropbox.com/s/ow0ntk3is4vwf ... 2.JPG?dl=0

Re: Extract Page from Scanned Image

Posted: 2015-09-24T10:05:32-07:00
by fmw42
If you have IM 6.8.9-10 or higher, you can use -connected-components to get a clean mask. This works for me in IM 6.9.2.3 Q16 Mac OSX (unix syntax)

Code: Select all

convert IMG_0102.JPG -fuzz 10% -fill white -opaque "gray(200)" -fill black +opaque white tmp.gif
convert tmp.gif -define connected-components:verbose=true -connected-components 4 null:
Objects (id: bounding-box centroid area mean-color):
0: 4608x3456+0+0 2517.2,1260.0 8181266 srgb(0,0,0)
1738: 3305x2221+405+1021 2072.1,2104.4 6055383 srgb(255,255,255) <-- largest white region
20369: 3360x228+466+3228 2189.2,3358.1 595495 srgb(255,255,255)
3309: 58x1708+771+1360 796.2,2251.9 6636 srgb(0,0,0)
....

Code: Select all

convert tmp.gif -define connected-components:area-threshold=6055383 \
    -connected-components 4 -threshold 0 mask.png
convert IMG_0102.JPG mask.png -compose multiply -composite IMG_0102_page.png

see
http://magick.imagemagick.org/script/co ... onents.php

Re: Extract Page from Scanned Image

Posted: 2015-09-25T14:28:03-07:00
by gvandyk
Thank you very much, that did it.

Now, for the deskewing... Will have a crack at it

Re: Extract Page from Scanned Image

Posted: 2015-09-25T14:46:16-07:00
by fmw42
see -deskew