Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top