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

Home » Public Forums » archive » 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
Shear transformation with Poly_2d [message #80546] Mon, 18 June 2012 08:15
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
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!

Cheers and happy shearing!

Helder
[Message index]
 
Read Message
Previous Topic: Re: Linking two or more IDL programs
Next Topic: Linking two or more IDL programs

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

Current Time: Wed Oct 08 16:06:54 PDT 2025

Total time taken to generate the page: 0.00240 seconds