Page 1 of 1

Splitting/cropping an image based on text vs drawing

Posted: 2012-04-04T22:56:15-07:00
by pfarrell
I have been using ImageMagick for a couple of months, and it has been amazing.
I can't figure if it can do what I need next.

I have a lot of images that are one page. At the top of the page is a lot of text. The bottom of the page is a drawing (technical drawing made by a draftsman). I need to crop the image throwing away all the text at the top, leaving only the drawing.

Here is a shortened URL to one sample source image:
http://bit.ly/FPRIBk

As you can see, its an image of one of my patents. I want to strip away all the legal text and just have an image of the bottom drawing.

Can ImageMagick do this kind of processing?

Thanks
Pat

Re: Splitting/cropping an image based on text vs drawing

Posted: 2012-04-04T23:03:18-07:00
by fmw42
One possibility is to scale the image down to one column (-scale). Look for the white spaces in the column. You can convert this one column to txt: format and search it with unix or windows commands. Get the coordinates for the last white space before the last non-white region. Then use that to crop out the bottom part of the image (-crop). Then trim that to get the minimum bounding area for the graphic (-trim).

see
http://www.imagemagick.org/Usage/resize/#scale
http://www.imagemagick.org/Usage/crop/#crop
http://www.imagemagick.org/Usage/crop/#trim
http://www.imagemagick.org/Usage/files/#txt

Re: Splitting/cropping an image based on text vs drawing

Posted: 2012-04-05T01:15:25-07:00
by anthony
Make sure when you -scale the image you use a '!' flag, to not-preverve the aspect ratio.

Re: Splitting/cropping an image based on text vs drawing

Posted: 2012-04-05T01:19:03-07:00
by anthony
Note for something a little fancier. You can use a user define distance function to get 'distance to first black pixel' in the first column. then crop that!

See example user distance functions in...
http://www.imagemagick.org/Usage/morpho ... tance_user

Distance functions is fast (just two passes through image).