2

I'm using ImageMagick to trim margins off of a scanned page.

The page has a black border and for our purposes looks something like this:

enter image description here

These are scans though, so there's often dust and other gunk making things less pretty. The command I'm using for the trimming is:

convert <filename> -crop \
  `convert <filename> -virtual-pixel edge -blur 0x15 -fuzz 40% -trim \
    -format '%wx%h%O' info:` +repage <filename>

This is mostly copied from various forums (I don't know what -format does, for instance). And it works well when the image has the black border and not much else outside it. Sometimes, however, the scans have things written in the margins or on top. I'd like to ignore everything outside the border but I don't quite know enough ImageMagick to tinker productively.

Any thoughts?

JacobEvelyn
  • 3,901
  • 1
  • 40
  • 51

1 Answers1

1

I ended up using a combination of some ImageMagick with using this line segment detector with some tricky parameters to find the borders and crop to those.

JacobEvelyn
  • 3,901
  • 1
  • 40
  • 51
  • In that case I have [a followup question](http://stackoverflow.com/questions/23299784/how-do-i-find-the-largest-nearly-white-rectangle-in-a-bitmap-with-imagemagick): how to do the line detection with ImageMagick? – reinierpost Apr 29 '14 at 14:08
  • Did my answer to your followup help? – JacobEvelyn Jun 08 '14 at 18:39
  • Not yet, sorry; I have been busy with other things, but I'm definitely going to try it! – reinierpost Jun 08 '14 at 21:56