9

I've got a whole lot of scanned images (> 500) the majority of which were scanned with the paper not completely square. They need to be rotated about 1-5 degrees to be aligned again.

Is there any software that does this? I know some scanner drivers do but mine doesn't seem to.

Update: It seems that thing I want here might be Image Registration software.

3

3 Answers 3

2

Imagemagick can handle batch processing, including rotation. Of course you'll need to know which image needs what amount (1-5 degrees) of rotation. You could either rotate all by 1 degree and then review for a further one degree, or check all at the start and put in folders of rotation amount.

-rotate degrees{<}{>} Apply Paeth image rotation (using shear operations) to the image.

Use > to rotate the image only if its width exceeds the height. < rotates the image only if its width is less than the height. For example, if you specify -rotate "-90>" and the image size is 480x640, the image is not rotated. However, if the image is 640x480, it is rotated by -90 degrees. If you use > or <, enclose it in quotation marks to prevent it from being misinterpreted as a file redirection.

1

You can use package deskew in python.

  1. Install the packege
pip install deskew
  1. Use it
import numpy as np
import skimage
import deskew


image = skimage.io.imread('input.jpg')
grayscale = skimage.color.rgb2gray(image)
angle = deskew.determine_skew(grayscale)
rotated = skimage.transform.rotate(image, angle, resize=True) * 255
skimage.io.imsave('output.jpg', rotated.astype(np.uint8))

https://github.com/sbrunner/deskew

0
0

Imagemagick now has a deskew command that can automatically detect how much to rotate. It can also optionally trim off the bits that rotate outside of a rectangular bounding box.

This example command is a good place to start:

convert input.png \
    -background black \
    -deskew 60% \
    -background black \
    -define trim:percent-background=0% \
    -fuzz 1% \
    -trim-rotate 180 \
    +repage \
    output.png

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .