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
Splitting/cropping an image based on text vs drawing
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Splitting/cropping an image based on text vs drawing
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
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
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Splitting/cropping an image based on text vs drawing
Make sure when you -scale the image you use a '!' flag, to not-preverve the aspect ratio.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Splitting/cropping an image based on text vs drawing
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).
See example user distance functions in...
http://www.imagemagick.org/Usage/morpho ... tance_user
Distance functions is fast (just two passes through image).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/