Page 1 of 1

Deskew image, give me the data

Posted: 2012-11-14T09:54:12-07:00
by jaffamuffin
Hi all

I am processing a form which has a very slight skew on it.

This form is scanned at 24bpp JPG

If I try to deskew the image, it doesn't work, presumably due to the colour/algorithm whatever

If I threshold the image to black and white, then deskew it deskews perfectly. However is there a way for me to 'read the angle' from this image and apply it back to the original colour scan?

I do this quite often using identify, as it's easier to process a form in B&W and then extract new geometry info from identify which to apply to the colour scan. Can I do this with deskew angle data ?


Thanks

Re: Deskew image, give me the data

Posted: 2012-11-14T17:04:58-07:00
by fmw42
This works for me on IM 6.8.0.4 Q16

# create 4 deg rotated zelda3.png

Image

convert zelda3.png -background white -rotate 4 zelda3_r4.png

# deskew
convert zelda3_r4.png -verbose -deskew 40% zelda3_r4_dskw.png
Affine Projection:
-distort AffineProjection \
'0.998053,-0.062378,0.062378,0.998053,0.000000,0.000000'
Affine Distort, FX Equivelent:
-size 148x148 -page -6-14 xc: +insert \
-fx 'ii=i+page.x+0.5; jj=j+page.y+0.5;
xx=+0.998053*ii -0.062378*jj +0.000000;
yy=+0.062378*ii +0.998053*jj -0.000000;
v.p{ xx-v.page.x-.5, yy-v.page.y-.5 }' \
zelda3_r4.png=>zelda3_r4_dskw.png PNG 138x138=>148x148 148x148-6-14 16-bit sRGB 81.9KB 0.030u 0:00.029


The result is deskewed. The -distort AffineProjection can be used to reproduce the deskew (unrotate), as I understand it. The -fx coefficients are equivalent in fx terms. see http://www.imagemagick.org/Usage/distor ... rt_verbose

It is my experience that -deskew does not work well on large rotations. But if you can make it work on grayscale, then you can use the verbose info to reproduce the deskew on the color image.

If you are on Linux, Mac OSX or Windows w/Cygwin, you might try my unrotate script at the link below. It works a bit better on larger rotates (<45 degrees and not so well on very small rotations). However, it will be slower than -deskew.