2

I have never used quaternions, so before trying on my problem I would like to know whether this is a good idea:

I want to interpolate an affine transformation: I have a set of points in a first 2D image I1 that are transformed by an affine transformation T into points in image I3. I want to introduce an intermediate image I2 between I1 and I3 and I would like to find out the transformation T' such that we should apply T' to the points of I1 to get to I2. Intuitively, T' should be "half" of the transformation T.

I read on a forum: 1-Transform the affine transformation matrix into quaternions 2- Use the Slerp interpolation on these quaternions 3- Convert them back to a matrix

Would that work on my 2D setting?

bigTree
  • 429
  • 1
    Yes, you can use quaternions in $2$-D transformations, but to me it seems unnecessarily complicated. Quaternions, being $4$-D, are usually used to represent $3$-D transformations. – Tim Ratigan Dec 18 '13 at 19:04
  • This is somewhat easier to do in the case of rigid motions an dilations... do you really need to do this for any $T\in GL(\Bbb R^2)$? – rschwieb Dec 18 '13 at 19:26
  • @rschwieb The objects I am using are actually rigid. How would this help? – bigTree Dec 18 '13 at 19:29
  • @bigTree Well, $O(\Bbb R,2)$ is a lot simpler than $GL(\Bbb R,2)$. Are you saying you'd be happy with rigid motions alone? – rschwieb Dec 18 '13 at 19:30
  • @rschwieb I agree. But now this is weird because I am using an existing program and I saw that the transformation matrices are clearly not just rotations (I don't have a rotation matrix). This is my mistake. The objects are not rigid – bigTree Dec 18 '13 at 19:32
  • @rschwieb Actually no. I need to treat the more general case where objects are not rigid – bigTree Dec 18 '13 at 19:44
  • Quaternions are not used to represent any 3d transformations. They are used to represent rotations. The group of rotations is $SO(3)$ and unit quaternions with quaternion multiplication form a double cover of that group. That's the sole reason they are useful. If you are doing anything other than 3d rotations (in particular arbitrary 2d transformations) chances are quaternions won't help you one bit. – Marek Dec 18 '13 at 19:46

2 Answers2

1

From my cursory reading of what slerp interpolation is, it sounds like it only deals with rotations, so it may or may not be helpful for general affine transformations.

It sounds like you wish to decompose the transformation $ax+b$ (where $a\in GL(\Bbb R,2)$ is the skewing and $ b\in \Bbb R^2$ is the translation, into a transformation $cx+d$ such composing $cx+d$ with itself results in the full $ax+b$ transformation, and just one application of $cx+d$ is the halfway point.

That would have to satisfy this: $c(cx+d)+d=ax+b$. Thus $c^2=a$ and $(c+I_2)d=b$.

Now there are formulas to compute the square root of some $2\times 2$ matrices, so using that you would be able to find a $c$ such that $c^2=a$. If additionally $c+I_2$ is invertible, then you would be able to find $d=b(c+I_2)^{-1}$, and that would furnish a $T'$ that satisfies $T'(T'(x))=ax+b$, and that seems like "half" of $T$ to me.

I can't see immediately what the conditions on $a,b$ allow this construction to work. (Edit: Marek has added insightful analysis along these lines in the comments, and shown that even a rotation by $\pi$ needs some special care.)


On the other hand, if "finding the square root of $T$" is too elaborate for you, you can always just split $ax+b$ into $ax$ and $x+b$.

Or if you prefer to avoid the fixed point in the first transformation, you can do $ax+b/2$ then $x+b/2$.

rschwieb
  • 153,510
  • 1
    Nice answer. As for when the method works: basically what you're doing is picking a point on the group of transformations, connecting it to the origin using the geodesic and picking a point in the middle. So the method works when the geodesic is unique (this happens almost always). Your statement that it works for rigid rotations is not quite correct. If you pick rotation by $\pi$ then there are two solution $\pi/2$ and $3\pi/2$. Your equation $(c + I_2)$ also degenerates in this case since $c=-I_2$. So there is inherent ambiguity of left vs. right. – Marek Dec 18 '13 at 20:02
  • 1
    As $GL(2)$ has the homotopy type of $O(2)$, this is the only ambiguity we get. The remaining degrees of freedom (scaling and skewing) can always be divided in half uniquely. – Marek Dec 18 '13 at 20:05
  • @Marek Ah! Thanks for providing that analysis! I overlooked the point about a rotation by $\pi$, but I gathered that there would be a workaround possible. – rschwieb Dec 18 '13 at 20:08
  • @Marek I would very much like to have that same intuition someday :) I'm not fluent in homotopy at all at the moment. – rschwieb Dec 18 '13 at 20:10
  • 1
    thank you for your kind words. Although I'm not as fluent as I'd like to be, I'm beginning to see the light here and there :) By the way, one piece of analysis was missing: we always stay in the positive-determinant component of $GL(2)$. That's why it's enough to work with $SO(2)$. Otherwise there would be a further ambiguity of adding a reflection. – Marek Dec 18 '13 at 20:15
  • @Marek If you had to say "I learned this idea from reading ___" what text would you recommend? And yeah, splitting a reflection using this idea does not seem feasible. – rschwieb Dec 18 '13 at 20:17
  • hm, not sure where I have the idea from. One source is definitely reading about K-theory. To classify rank $k$ vector bundles on $S^n$, you can consider maps from the equator (which is $S^{n-1}$) to $GL(k)$. This tells you how to glue the north and south portions of the bundle (each of which is a trivial bundle because disk is contractible). So you need to find the homotopy type of $GL(n)$ and it turns out it's $O(n)$ resp. $U(n)$ for reals resp. complexes (by Gramm-Schmidt). So in the end one is studying homotopy groups of classical groups. – Marek Dec 18 '13 at 20:27
  • I know I read about some parts of the above on wikipedia and in Hatcher's book on Vector Bundles and K-theory (there are many other fantastic insights in that book). But I got much of my intuition from Bott and Tu's Differential Forms in Algebraic Topology. That one is a gem. – Marek Dec 18 '13 at 20:29
  • @Marek Thank you! I intend to check out Bott+Tu. – rschwieb Dec 18 '13 at 20:54
0

There was an excellent answer to your previous question, where "John" showed you how to decompose your transformation into rotate, shear, and scale pieces. To get the "half-way" transformation, just take the values in the rotation, shear, and scale matrices and divide them by two.

By the way, what you're doing has a name -- it's called "tweening". If you look up this term, you'll find a huge amount of literature.

You don't need to use quaternions for 2D transformations, and you don't need to know anything about vector bundles or homotopy groups, either.

bubba
  • 43,483
  • 3
  • 61
  • 122