Page 1 of 1

Straighten an image

Posted: 2009-06-01T10:36:41-07:00
by pitosalas
RE: http://www.salas.com/elect/testballot1.tif

This as you can see is an image from a USA voting ballot. They are scanned by a high speed scanner. They are not always perfectly vertical.

I need help with a good way to 'straighten' an image like the one attached. Basically, it seems like if I can identify the black 'timing' mark in the top left edge, and the corresponding last 'timing mark' in the bottom left, I could rotate the image fractionally to make sure it's exactly straight so I can use specific coordinates to look for other features.

I suspect that this is a fairly easy task but I can't figure out the 'right' way to do it.

If anyone could give me some pointers that would be appreciated!

Pito

Re: Straighten an image

Posted: 2009-06-01T11:11:22-07:00
by fmw42
IM has a function deskew for doing that. See http://www.imagemagick.org/script/comma ... php#deskew

I also wrote a bash script, unrotate, that might work. see http://www.fmwconcepts.com/imagemagick/index.html

unrotate testballot1.tif testballot1_tmp1.gif

http://www.fmwconcepts.com/misc_tests/t ... 1_tmp1.gif

Re: Straighten an image

Posted: 2009-06-01T11:33:02-07:00
by pitosalas
Thanks!

How come you wrote your own script if there is a built-in function?

I did a test and the built in function seems very slow. Is that inherent in how hard it is to deskew?

Re: Straighten an image

Posted: 2009-06-01T13:18:18-07:00
by fmw42
At the time I wrote it, the IM function -deskew was not available.

My original intent was for color pictures, not for b/w text. I believe that the IM function -deskew was especially written to handle slightly rotated text.

My script is slow, because it is a "script" and not a compiled function with many calculations and multiple IM function calls. It uses a different algorithm than the IM function -deskew. So if -deskew works for you, I would expect it to be more efficient.

Re: Straighten an image

Posted: 2009-06-01T14:25:17-07:00
by pitosalas
I wasn't implying that your script was slow.

The built in function seems rather slow to me (Image.deskew)

Sorry for implying otherwise.

Re: Straighten an image

Posted: 2009-06-01T18:54:38-07:00
by fmw42
No offense taken. The fact is that my script is slow relatively speaking when compared to a proper full blown coded function.