comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Shear transformation with Poly_2d
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Shear transformation with Poly_2d [message #80544 is a reply to message #80543] Mon, 18 June 2012 12:17 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Monday, June 18, 2012 11:15:48 AM UTC-4, Helder wrote:
> Hi,
> I'm not going to post a question, rather a solution... The reason is that I was fighting with this a few hours and I thought it would be nice to show a solution to anybody who might care about this.
> I was a bit annoyed that of the affine transformations (scaling, rotation, translation and shear) one is missing... The transformations like scaling and rotation can be accessed using ROT that then calling POLY_2D that actually does the work. Translation can be done (easily) with shift (although this is only possible using integer translation, for non integer translations, the procedure described below may also be used...).
> What is missing is of course shear. If you look in text books you find a matrix for shear that looks like:
> ShearVertical = [[1,0,0],[Vert,1,0],[0,0,1]]
> where Vert is the degree of vertical shear.
> I thought it would be nicest to get this sorted by using this matrix, but I just couldn't get this to work without loops or having to rewrite basic math code... not nice and given that IDL is well suited for image processing I thought that there has to be an IDL way for this.
>
> So here we go. POLY_2D give in the help indications on how to use it and some examples (of course not shear).
> If you want to implement a shear transformation, then you would have to do the following.
>
> Img = DIST(200)
> WINDOW, XSIZE=405,YSIZE=200
> TVSCL,Img
> VertShear = 20.0
> KX = [[0.0, 0.0],[1.0, 0.0]]
> KY = [[VertShear, 1.0],[-VertShear/100.0, 0.0]]
> TVSCL,POLY_2D(img,KX, KY,cubic=-0.5), 205, 0, /DEVICE
>
> This works fine if you want to shear the image in the middle. If you want shear somewhere else, I could only manage that using POLYWARP.
> In this case, you set some coefficients that act as transformation points (4 is the minimum number of points):
>
> s = SIZE(Img,/DIMENSIONS)
> Offset = [50,0] ;In pixels
> XI = [0, 0, s[0]-1, s[0]-1]+Offset[0]
> YI = [0, s[1]-1, 0, s[1]-1]+Offset[1]
> XO = XI
> VertShear = 20.0
> YO = YI + [-VertShear, -VertShear, VertShear, VertShear]
>
> Then with POLYWARP you can retrieve the coefficients KX and KY and use them as above.
>
> POLYWARP, XI, YI, XO, YO, 1, KX, KY
> TVSCL,POLY_2D(Img,KX, KY,cubic=-0.5), 205, 0, /DEVICE
>
> The shearing point is now moved 50 pixel to the right (positive).
> There is probably an easy way to obtain these coefficients in a smooth mathematical way... Happy to hear suggestions!

I think the standard way to implement a shear or rotation about a different origin, is to compose a series of transformations: translate, shear, untranslate.

You can't do translations with a simple matrix transformation. A "translation matrix" can be designed by using an (N+1)x(N+1) matrix and using homogeneous coordinates.
http://en.wikipedia.org/wiki/Translation_%28geometry%29
Not that this is more efficient, but sometimes it can simplify the notation.

Craig
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDL DE startup error on OS X
Next Topic: Oject programming error in non-object program

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 00:34:22 PDT 2025

Total time taken to generate the page: 1.12054 seconds