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 #80543 is a reply to message #80542] Tue, 19 June 2012 05:52 Go to previous messageGo to previous message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Monday, June 18, 2012 9:17:22 PM UTC+2, Craig Markwardt wrote:
> 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

Yes, you are absolutely right. However, when dealing with affine transformations the translation is also included as an "affine matrix":
Translation = [[1,0,0],[0,1,0],[tx,ty,1]]
where an affine transformation transforms spatial coordinates (v,w) of the source image to (x,y) in the transformed image. The notation goes like:
[x,y,1] = [v,w,1] TransfMatrix
I have taken my geometry classes a long time ago, but I suppose that in this case the pixel coordinates are two and the matrix has three components, therefore fitting to what you said about using a (N+1)x(N+1) transformation matrix for translations (the last column and last row are all zeros and a one on the diagonal for all transformations except for the translation where numbers come in...). Another way of describing this is saying that affine transformations are linear transformations followed by a translation.
I took the above transformation matrix treatment from Digital Image processing of Gonzales/Woods.

I find it a pity that there is no clear/direct way to implement shear transformations in IDL. As I said, it is possible to do rotation, scaling and translation (with some limitations...), but not shear. I thought that they would be all fit in the same chapter. Even nicer would be the possibility to feed in transformation matrices directly. One could then combine the matrices accordingly and perform the transformation only once. If, for instance, I would like to first rotate and then translate, I would calculate the matrix and then perform the operation, saving computation time (1 matrix calculation and 1 transformation).

At the moment I'm busy with something else, but I'll check if effectively the image is also translated when doing the shear rotation as describe above. So far I have the feeling that this is working, but I will cross check by doing separating the two operations and comparing results.

Helder
[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 10:07:19 PDT 2025

Total time taken to generate the page: 0.64076 seconds