Auto-crop part inside variable sized box in images

0

I have a lot of scanned images in which I want to auto-crop the region inside the largest rectangle or box. This image shows some examples.
enter image description here
The last one is what I would like the output to be like.

Since the input images will vary in size and dimension, as well as in the number of total rectangles and how they are arranged, I figured one approach would be to use some kind of line detection. With that information we could detect the largest rectangle in the image and use that as the cropping rectangle. The next step would just be to use imagemagick with the -trim option I guess.

Is this a valid approach, and if so, how can I implement it?

If not, what other methods are good?

irri

Posted 2015-11-26T04:53:26.180

Reputation: 1

Answers

0

I actually found a solution to this by myself. On Fred's ImageMagick Script webpage he has a script called Innercrop. I get good result by using it like this:

#!/bin/bash
for f in $(ls *.jpeg); do 
    ./innercrop -m crop -o white -p 1 -f 10% ${f} tmp_${f}
    convert -bordercolor black -shave 5x5 -fuzz 30% -trim tmp_${f} -quality 100 +repage result_${f}
    rm tmp_${f}
done

irri

Posted 2015-11-26T04:53:26.180

Reputation: 1

I'm guessing that's a bash script? – jiggunjer – 2015-11-26T09:21:40.603