Page 1 of 1

(de)skew / shear images

Posted: Sat Oct 22, 2016 9:47 am
Is it possible to do a image transformation using live code as described in this article on stack overflow ?

http://stackoverflow.com/questions/9470 ... ransform3d

My first idea was to use affine transform of mergext av, but it seems to be beyond my scope

Re: (de)skew / shear images

Posted: Tue Oct 25, 2016 12:33 am
If this is a real distortion, that is including perspective transform, then it is not doable by an affine transform like skew/shear (which is available in LC Builder for paths/polygons), simply because a perspective transform is not affine.

TMHO, the best source for 'distortion' is in imagemagick's documentation, describing also all the problems ...

Skew/shear only for polygons.
The formulas for shearing in x- or y-direction are

Code: Select all

``````-- p0 are the points of a polygon
-- b0 is the 'shear-factor', positive or negative, 0 is no shear
function shearX p0,b0
if b0=0 then return p0
put b0*pi/180 into b
repeat for each line L in p0
if L is empty then put CR & CR after p1
else put cr & (round(item 1 of L - b*item 2 of L),item 2 of L) after p1
end repeat
return char 2 to -1 of p1
end shearX

function shearY p0,b0
if b0=0 then return p0
put b0*pi/180 into b
repeat for each line L in p0
if L is empty then put CR & CR after p1
else put cr & (item 1 of L, round(item 2 of L + b*item 1 of L)) after p1
end repeat
return char 2 to -1 of p1
end shearY``````
See for an interactive example my HTML5 demo ('Paul Klee clock').

Skew/shear only for an image.
Transform the imagedata as follows:
Determine the pixels of the image as points (x,y), transform them as above and set the color of the transformed pixels to the color of the originals.

LC will be not very fast with that (imageJIT 2.0, appearing in November will have that faster).

If you wish to have a skewed/sheared rectangle/polygon frame filled with an image you may use my polygon widget -- adjust it manually in editMode or by setting the points by script (use functions above).

[p.s. You can ask support at runrev.com for a different forum-user name, if you like ]

Re: (de)skew / shear images

Posted: Thu Oct 27, 2016 8:06 pm

My goal is, to deskew an image of a letter or article, to send it to an internal web service of mine wich offers an ocr engine.

Any ideas?

Re: (de)skew / shear images

Posted: Thu Oct 27, 2016 10:00 pm
I got the 'mimu' now, hi Michael.

There are a lot of apps in the folks, most non-free, that do nothing else then "unrotate". They call it "deskew" but the images they are showing are simply rotated, no additional skew.

You can have this for free at a high quality from imageMagick, see (the Weinhaus-scripts) http://www.fmwconcepts.com/imagemagick/ ... /index.php
Choose "unrotate", there is even an "unperspective" there (scroll web page down after selecting the terms).

You could try one or both via LC's shell and tell us how much the OCR is improved?

If there is also 'real' skew and perspective in it (as in the examples of F. Weinhaus for "unperspective") then this may be done by a "Hough transform" which is in general not trivial. This also needs good computation speed, LC will not be fast enough for images of letter size (or DIN A4 size). But I think about trying to implement this into imageJIT, to have it even faster than imageMagick.

In case you are organizing a LiveCoder meeting in Berlin next year, this would be, of course, a special present for you

Ciao, Hermann

Re: (de)skew / shear images

Posted: Fri Mar 10, 2017 11:29 am
See "Sample Stacks" (LC toolbar) or livecodeshare.

If you use it, then it's your turn.
What did you say is the targeted date for the first LiveCoder meeting in Berlin?