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:
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.