Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Can I auto-rotate an image that contains mainly text? Maybe via OCR? The algorithm or whatever needs to scan the image and decide if it has to rotate it 90°, 180° or 270°

I want to include this feature into an existing PowerShell script, so command-line ability is mandatory.

I'm open for ImageMagick solutions

Example

enter image description here
Click to enlarge

I have already read the following SO questions. But they rotate photos.
and I'm only trying to rotate pure text scans which have no EXIF metadata.

share|improve this question

2 Answers 2

You want the ImageMagick convert utility. Just run

convert -rotate 90 image.png

and it will be rotated 90 degrees and saved back as the same file name.

share|improve this answer
    
Well, I thought it is obvious from the question (» OCR). Apparently not. Sometimes the scans must be rotated 270°, 90° or 180°. That is not fixed –  nixda Mar 19 at 19:58
    
@nixda There is also an -auto-orient option that may be of use - I haven't used it, so I don't know how accurate it is. Sorry, I didn't pick up from your original question that they weren't all in the same orientation. –  MattDMo Mar 19 at 20:02
    
The documentation says it's using EXIF data. So this is no solution. If the EXIF profile was previously stripped, the -auto-orient operator will do nothing. –  nixda Mar 20 at 9:27

Not the most elegant way, but you could try to OCR in all four orientations and whichever one has the least amount of gibberish is the correct one. I did some quick searching, and I found a few references which discuss using such a technique, for example:

Phase two of document correction is the contextual auto-rotate. Using a full-page OCR read at several orientations the software can determine at which orientation the quality of the read is best. This is the most accurate way to rotate a document. Documents with little text, or text at various angles are the only risky documents. In these cases, the software chooses the orientation of the MOST readable text.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.