An introduction to my little scan rotation program.

In case you're asking yourself right about now "Why could I need a program to do that?", you can probably safely ignore this page and the program altogether.
If, however, you are just as tired as I were of rotating thousands of scans, read on...

Now, it's not that PS does a bad job or anything, but it's just so time consuming to align well. Plus it's boring as hell. And doing boring automated tasks is something computers are quite good at, so why not let them help out a bit?

Anyway, some disclaimers before we start:
I should warn you straight away that the user interface is atrociously ugly. (Yes, it's meant to be that way.)
Error handling is slightly rudimentary. It's not like it'll suddenly just puke and erase your entire drive, but it's possible that you may have odd error messages.
It works totally fine for me, but that's no guarantee that it will for you. Verify the output, at least the first times you use it.
The actual program file is huge. It's a feature of the programming language I used.

Now that you've been warned, on to the actual info.


The program comes as a single file executable. No installer. No Registry settings. No .ini file.
Here's a link to download the program zip, if you haven't already. (Current version is 0.6.1, made on 2009-02-16)


Delete the program file.

Running it

So, you say, that's all well and good, but how do I actually run it?
Good question, thought you'd never ask.
You can start it with just:
which picks up all the files the program likes, in the directory you run it from.
rotate filename
which rotates one single file by the name specified.
rotate *.extension
which picks up all files with that extension
or maybe a mix:
rotate *.jpg spiffy_scan_017.png crapmanga_*.tif
Default input file formats are PNG, TIFF, or JPEG. Output file formats are PNG and TIFF. (Outputting to a lossy format will never be supported.)
PSD files are actually somewhat supported as input. But it varies over different files whether it works or not, so they're not automatically picked up. Try:
rotate *.psd
It may work for you (it works for the files I've made myself, but not some others).

All files end up in a subdirectory called
Files by the same names as the output files, that are already in that directory, are overwritten without mercy.

Running it (simplified version)

Double click on the program. The rest will be obvious.

Controlling it

Unfortunately for me, and maybe you, making a totally automatic program for scan rotation, that's failsafe enough, is probably much more work than I'm ever going to put into this.
So, you have to tell the program where to start looking for edges yourself. A rough estimate is enough.
(This is where it gets tricky to explain in words. More on this later, in the picture part.)

The commands are:
Left mouse buttonSet first point to search from
Right mouse buttonSet second point to search from
Middle mouse buttonRotate, save and go to next file (or if two points haven't been set, just skip to next file)
EnterRotate, save and go to next file
wRotate, save and go to next file
Right/Left arrow keysGo to next/previous file without writing anything
SpaceReverse search direction (the direction is reset at every mouse click)
-Reverse search direction
aAdd to measurement average
+Add to measurement average
rReset measurement average
0Reset measurement average
tTurn the image around 180 degrees before aligning it
As you can see, there are alternatives for left-handed people, but only for the most used keys.

New in version 0.6.1 is the t command, which turns the image upside down.

Hands on

Since it's bloody impossible to explain how you use it in just words (I've tried), I'll do it with the help of some screenshots instead.

Here's what I start with:

The easiest way to run the program for novices is of course to just place the scans in the same directory and double click the program.

Right, now I've done that, and up comes the first image. Never mind that the resizing looks ugly in the window, it's only for fast display.
(What's displayed there is not how the actual scan looks at any part of the processing.)

Now this is the tricky part to explain.
In order for the program to know where to look for edges, you have to give it something to start with.
For instance, in this scan I want to align to the right panel edges. I find that I almost always want to align to the longest vertical "line" in the scan, which is quite often the panel edges that are towards the spine of the book.
So, in this case, aim somewhere to the right of the lines you want to align to, but to the left of any crap you want the program to ignore.

And to clear something up, by default, the program always searches inwards, towards the middle of the page.
If you find that you need to search in the other direction, just let it do a default search first, then press space.

Here's roughly where I think you should aim, in this scan:

You don't have to aim that far apart, but the precision is better the further apart the points are. (It has nothing to do with the program, really, it's just geometry.)
Don't put the starting points all the way out to the edge of the page, though, I've noticed that pretty much all lines tend to bend there. (Strange but true. One of these days I'll also figure out why.)

Okay, so now I've clicked the left mouse button at the top there somewhere and the right mouse button at the bottom.
Here's the result:

The end points of the red line represent where I clicked. This is where the program starts to search for edges.
The blue line represents a line that the program thinks it should align to.
The blue text displays the current misalignment angle.
Rounding errors in the displaying may make it seem like the blue line is slightly off from the line you want, but what's important is the angle of the line, not exactly where it is.

This is perfectly fine, I could just click the middle button (or press 'w' or Enter) right now so the image is saved and the program goes to the next scan.
But just to show you that you don't have to be all that super careful where you click, let's say I wasn't happy with that but wanted to adust the initial guess. Fine, just click some more, and the program measures from new points instead.
Like so:

As you mave have noted, the angle changed here. Shock! Horror! Is the program not measuring correctly!?
Before you let your imagination run off in that direction and get the urge to ask me stupid questions about this, take a moment or two to think about how little 0.01 degrees really is.

But anyway, enough with that particular silliness. It's time to click the middle button.
What happens then is that the program reads the next scan in its list of things you wanted to rotate, while at the same time rotating the old scan according to its findings and saving it in the subdirectory.

Right then, onwards to a couple of more examples.

Note that the edge I want to align to doesn't go all the way across the scan, so I only choose the useful bit.

Now, this isn't the best example for this, since the page has fairly straight angles, but here goes...

From version 0.6.0, I added a feature to enable measuring an unlimited number of edges. It works like so:
1) Measure one edge just like usual.
2) Press 'a' or '+' (for Add), and the current measurement will be added to an average.
3) Done yet? If not, go to 1.
4) Press 'w', Enter or click the middle button to save the rotated scan.

If you want to start over again, or just align the normal way, press 'r' or '0' (for Reset), and the current average will be removed.

Here's how it looks in action:

The blue text on the left works just like normal, and the green text on the right shows the current average (if there is at least one measurement added to it).
A trick you can use with this is to add edges you judge to be more important several times to the average. They'll then have more weight in the calculation of the average misalignment than edges added just once.

A word of warning, though. Quite a few scans just end up looking crooked if you get carried away and start to measure every single slightly vertical or horizontal line in them and then averaging the result. Restrict yourself to long lines. Using the panel edges near the left and right sides of the page is almost always safe. For many images, you get no visible gain whatsoever from the averaging approach. So, don't use the feature just because it's there. It can be fairly useful at some times, but much less so at others. (It can even be harmful, if you use it completely without thinking.)

Okay, since this was the last image, I just press the middle button one last time and then wait for the program to exit. This is actually important, believe it or not. It takes a little "extra" time here, but rest assured the program is most likely doing something useful. (It actually takes about the same time to save all scans at the same size. But since the program is multithreaded, you don't notice the time it takes to save so much, until the last scan.)

Known limitations

It does not work with scans that have no clear lines to align to. (Well, duh ;) It's for instance better to rotate double pages with printing that goes all the way to the spine of the book, and similar things, manually in PS.
Error handling is so-so. If you actively try to trick it, you will probably succeed.
PSD support is sketchy.
PNG files do not keep their dpi info.

That's about it, then. I'd give you a contact address for bug reports and such, but if you use this program, chances are you already know how to reach me ;)