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
Straighten an image
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Straighten an image
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
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
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?
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Straighten an image
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.
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
I wasn't implying that your script was slow.
The built in function seems rather slow to me (Image.deskew)
Sorry for implying otherwise.
The built in function seems rather slow to me (Image.deskew)
Sorry for implying otherwise.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Straighten an image
No offense taken. The fact is that my script is slow relatively speaking when compared to a proper full blown coded function.