Hi,
I have been using Tony Parker's great Reorient3TP plugin to define arbitrary planes in a stack of images on the basis of picked points. Works really nicely and can generate a transformation matrix so I can recall the slice location using TransformJ Affine. Can anyone advise me on the following: If I open the same image stack twice - stack v1 - define slice plane A on the basis of picked points and output the affine transformation stackv2 - define slice plane B on the basis of picked points and output the affine transformation Is there any way to calculate the angle between planes A and B from the two transformation matrices? any guidance/insights would be greatly appreciated cheers nathan -- ---------------------------------------------------------- Dr. Nathan Jeffery Department of Musculoskeletal Biology Institute of Ageing& Chronic Disease University of Liverpool Sherrington Bld. Ashton Street Liverpool L69 3GE Office: 0151 794 5514 Fax: 0151 794 5517 e-mail: [hidden email] http://pcwww.liverpool.ac.uk/~njeffery/ ------------------------------------------------------- |
Hi Nathan,
On Thu, 16 Feb 2012, Nathan Jeffery wrote: > I have been using Tony Parker's great Reorient3TP plugin to define > arbitrary planes in a stack of images on the basis of picked points. > Works really nicely and can generate a transformation matrix so I can > recall the slice location using TransformJ Affine. > > Can anyone advise me on the following: > > If I open the same image stack twice - > > stack v1 - define slice plane A on the basis of picked points and output the > affine transformation > stackv2 - define slice plane B on the basis of picked points and output the > affine transformation > > Is there any way to calculate the angle between planes A and B from the two > transformation matrices? Not sure that I fully understand, but here is my take: the transformation matrices are basically made up of the vectors to which the X, Y and Z unit vectors are mapped. (If they contain a 4th vector, that is the translation, which does not matter for the angle calculation.) So if you want to know the angle between the images of the XY plane as per the two matrices, you can measure the angle between the corresponding normal vectors instead. Now, I am assuming that the transformations are rigid rotations? In that case, the normal vectors are what the Z unit vector is mapped to. Given those two mapped unit vectors (which are still unit vectors if I understand the problem correctly), you can calculate the cosine of the angle by taking the scalar product of the vectors. Does that solve your issue? Johannes |
I have never used the TransformJ package, but I know a thing or two about
linear transformations. To implement Johannes suggestion, try the following: Multiply the affine transform (http://www.imagescience.org/meijering/software/transformj/affine.html) for each output plane by the vector (0,0,1,0); this is the z-axis of the input stack. The first three components of the result vector (axz, ayz, azz) are the components of the vector normal to the output plane in the coordinates of the input stack. Do this for each of the two output planes to get two normal vectors: (axz1, ayz1, azz1) and (axz2, ayz2, azz2). Calculate the dot product of these two vectors: axz1*axz2+ayz1*ayz2+azz1*azz2 The angle between the normal vectors (and therefore the angle between the planes) is the inverse cosine of the dot product. Of course, test your calculations by running a few cases with known angles. -- David M. Gauntt, Ph.D. Associate Professor, Division of Medical Physics and Engineering UAB Department of Radiology mailto:[hidden email] 205-975-3777 On 2/16/12 11:24 AM, "Johannes Schindelin" <[hidden email]> wrote: >Hi Nathan, > >On Thu, 16 Feb 2012, Nathan Jeffery wrote: > >> I have been using Tony Parker's great Reorient3TP plugin to define >> arbitrary planes in a stack of images on the basis of picked points. >> Works really nicely and can generate a transformation matrix so I can >> recall the slice location using TransformJ Affine. >> >> Can anyone advise me on the following: >> >> If I open the same image stack twice - >> >> stack v1 - define slice plane A on the basis of picked points and >>output the >> affine transformation >> stackv2 - define slice plane B on the basis of picked points and >>output the >> affine transformation >> >> Is there any way to calculate the angle between planes A and B from the >>two >> transformation matrices? > >Not sure that I fully understand, but here is my take: > >the transformation matrices are basically made up of the vectors to which >the X, Y and Z unit vectors are mapped. (If they contain a 4th vector, >that is the translation, which does not matter for the angle calculation.) > >So if you want to know the angle between the images of the XY plane as per >the two matrices, you can measure the angle between the corresponding >normal vectors instead. > >Now, I am assuming that the transformations are rigid rotations? In that >case, the normal vectors are what the Z unit vector is mapped to. > >Given those two mapped unit vectors (which are still unit vectors if I >understand the problem correctly), you can calculate the cosine of the >angle by taking the scalar product of the vectors. > >Does that solve your issue? >Johannes |
Hi David,
On Thu, 16 Feb 2012, David M Gauntt wrote: > Multiply the affine transform > (http://www.imagescience.org/meijering/software/transformj/affine.html) > for each output plane by the vector (0,0,1,0); Multiplying a matrix by (0 0 1 0)^T is tantamount to extracting the third column from the matrix. > this is the z-axis of the input stack. More precisely: it is the unit vector in the positive direction of the z axis, but I think it is the axis of the output stack. Ciao, Johannes |
Johannes,
>Multiplying a matrix by (0 0 1 0)^T is tantamount to extracting the third >column from the matrix. Yes; the result that I quoted was the transpose of the third column of the affine transform. > >> this is the z-axis of the input stack. > >More precisely: it is the unit vector in the positive direction of the z >axis, but I think it is the axis of the output stack. > That is true, although I don't know if there is a technical distinction between the z-axis and the unit vector in the positive z-direction. >-- David M. Gauntt, Ph.D. Associate Professor, Division of Medical Physics and Engineering UAB Department of Radiology mailto:[hidden email] 205-975-3777 |
In reply to this post by dscho
Thanks to David & Johannes,
This leads us to the real problem. I thought I was doing it wrong, hence my original question. I have two test arbitary planes that I know are 90degrees apart. They were originally defined by euler angles - plane 1 = (217, 51, 4 degrees in x, y, z) plane 2 = (18, 64, 227 degrees in x, y, z) If I put these angles in the transformJ affine create rotate function, transformj generates the rotation matrices and finds the planes perfectly! If I then multiply by (0,0,1) I am left with: vector1 = -0.661124967 0.557054233 -0.502597611 vector2 = -0.808975604 -0.414414938 0.416915736 the acos of the dot product = 84.58082316 which is not 90 degrees! In 9/10 cases it calculates the correct angle. Any ideas/suggestions? best nathan ---------------------------------------------------------- Dr. Nathan Jeffery Department of Musculoskeletal Biology Institute of Ageing & Chronic Disease University of Liverpool Sherrington Bld. Ashton Street Liverpool L69 3GE Office: 0151 794 5514 Fax: 0151 794 5517 e-mail: [hidden email] http://pcwww.liverpool.ac.uk/~njeffery/ ------------------------------------------------------- ________________________________________ From: ImageJ Interest Group [[hidden email]] on behalf of Johannes Schindelin [[hidden email]] Sent: 16 February 2012 19:27 To: [hidden email] Subject: Re: Reorient3TP & transformations Hi David, On Thu, 16 Feb 2012, David M Gauntt wrote: > Multiply the affine transform > (http://www.imagescience.org/meijering/software/transformj/affine.html) > for each output plane by the vector (0,0,1,0); Multiplying a matrix by (0 0 1 0)^T is tantamount to extracting the third column from the matrix. > this is the z-axis of the input stack. More precisely: it is the unit vector in the positive direction of the z axis, but I think it is the axis of the output stack. Ciao, Johannes |
I am not a fan of Euler angles, so I don't have much experience with them.
How do you know that these angles define planes 90deg apart? There are multiple ways to define Euler angles, no two of which lead to the same transformation. It may be that Reorient3TP may be using a different definition than you are using. -- David M. Gauntt, Ph.D. Associate Professor, Division of Medical Physics and Engineering UAB Department of Radiology mailto:[hidden email] 205-975-3777 On 2/16/12 2:22 PM, "Jeffery, Nathan" <[hidden email]> wrote: >Thanks to David & Johannes, > >This leads us to the real problem. I thought I was doing it wrong, hence >my original question. > >I have two test arbitary planes that I know are 90degrees apart. They >were originally defined by euler angles - >plane 1 = (217, 51, 4 degrees in x, y, z) >plane 2 = (18, 64, 227 degrees in x, y, z) > >If I put these angles in the transformJ affine create rotate function, >transformj generates the rotation matrices and finds the planes perfectly! > >If I then multiply by (0,0,1) I am left with: >vector1 = -0.661124967 0.557054233 -0.502597611 >vector2 = -0.808975604 -0.414414938 0.416915736 > >the acos of the dot product = 84.58082316 > >which is not 90 degrees! > >In 9/10 cases it calculates the correct angle. > >Any ideas/suggestions? >best >nathan > > > > > > >---------------------------------------------------------- >Dr. Nathan Jeffery >Department of Musculoskeletal Biology >Institute of Ageing & Chronic Disease >University of Liverpool >Sherrington Bld. >Ashton Street >Liverpool L69 3GE > >Office: 0151 794 5514 >Fax: 0151 794 5517 >e-mail: [hidden email] >http://pcwww.liverpool.ac.uk/~njeffery/ >------------------------------------------------------- >________________________________________ >From: ImageJ Interest Group [[hidden email]] on behalf of Johannes >Schindelin [[hidden email]] >Sent: 16 February 2012 19:27 >To: [hidden email] >Subject: Re: Reorient3TP & transformations > >Hi David, > >On Thu, 16 Feb 2012, David M Gauntt wrote: > >> Multiply the affine transform >> (http://www.imagescience.org/meijering/software/transformj/affine.html) >> for each output plane by the vector (0,0,1,0); > >Multiplying a matrix by (0 0 1 0)^T is tantamount to extracting the third >column from the matrix. > >> this is the z-axis of the input stack. > >More precisely: it is the unit vector in the positive direction of the z >axis, but I think it is the axis of the output stack. > >Ciao, >Johannes |
Thanks again David,
I used the euler angles just as a convenient way to define the arbitrary planes in a test dataset I created a block of black (0) voxels (300x300x325). I then used TransfromJ affine create, rotate to generate the first plane (rotate 217, 51, 4) and painted it white. I then revert back to the original stack using the inverse transform and repeat the process for plane 2 (18, 64, 227). I end up with a stack of images with two arbitrary planes painted through it. Next I created a 3D reconstruction of the planes and rotated the 3D until the planes were parallel in orthographic view (not perspective). I then take the angle between the two planes which turns out to be exactly 90degrees (hadn’t planned this!). Finally, I used Reorient3TP to find the planes again. The matrices are the same as those generated by transfromJ affine create above and it finds the planes perfectly. However, if I then plug these numbers into the calculation I get 84.58 degrees not 90. What I am having trouble working out is why the transform matrices will find the planes perfectly but will not calculate the correct angle? I have repeated process several times to check each stage. Also, I have repeated for different planes and get the correct answer. Any ideas? ________________________________________ From: ImageJ Interest Group [[hidden email]] on behalf of David M Gauntt [[hidden email]] Sent: 16 February 2012 21:00 To: [hidden email] Subject: Re: Reorient3TP & transformations I am not a fan of Euler angles, so I don't have much experience with them. How do you know that these angles define planes 90deg apart? There are multiple ways to define Euler angles, no two of which lead to the same transformation. It may be that Reorient3TP may be using a different definition than you are using. -- David M. Gauntt, Ph.D. Associate Professor, Division of Medical Physics and Engineering UAB Department of Radiology mailto:[hidden email] 205-975-3777 On 2/16/12 2:22 PM, "Jeffery, Nathan" <[hidden email]> wrote: >Thanks to David & Johannes, > >This leads us to the real problem. I thought I was doing it wrong, hence >my original question. > >I have two test arbitary planes that I know are 90degrees apart. They >were originally defined by euler angles - >plane 1 = (217, 51, 4 degrees in x, y, z) >plane 2 = (18, 64, 227 degrees in x, y, z) > >If I put these angles in the transformJ affine create rotate function, >transformj generates the rotation matrices and finds the planes perfectly! > >If I then multiply by (0,0,1) I am left with: >vector1 = -0.661124967 0.557054233 -0.502597611 >vector2 = -0.808975604 -0.414414938 0.416915736 > >the acos of the dot product = 84.58082316 > >which is not 90 degrees! > >In 9/10 cases it calculates the correct angle. > >Any ideas/suggestions? >best >nathan > > > > > > >---------------------------------------------------------- >Dr. Nathan Jeffery >Department of Musculoskeletal Biology >Institute of Ageing & Chronic Disease >University of Liverpool >Sherrington Bld. >Ashton Street >Liverpool L69 3GE > >Office: 0151 794 5514 >Fax: 0151 794 5517 >e-mail: [hidden email] >http://pcwww.liverpool.ac.uk/~njeffery/ >------------------------------------------------------- >________________________________________ >From: ImageJ Interest Group [[hidden email]] on behalf of Johannes >Schindelin [[hidden email]] >Sent: 16 February 2012 19:27 >To: [hidden email] >Subject: Re: Reorient3TP & transformations > >Hi David, > >On Thu, 16 Feb 2012, David M Gauntt wrote: > >> Multiply the affine transform >> (http://www.imagescience.org/meijering/software/transformj/affine.html) >> for each output plane by the vector (0,0,1,0); > >Multiplying a matrix by (0 0 1 0)^T is tantamount to extracting the third >column from the matrix. > >> this is the z-axis of the input stack. > >More precisely: it is the unit vector in the positive direction of the z >axis, but I think it is the axis of the output stack. > >Ciao, >Johannes |
Jeffrey,
As I understand TransformJ Affine create, the input parameters are not Euler angles but rather 3x3 matrices; I assume that you used the Euler angles to create the matrices. I would trust the result of the calculation based on matrices; it is the 90 degree result that I would question. I may use this as an opportunity to learn better how to manipulate stacks. 1) What plugin did use use to make the original 300x300x325 block? 2) How exactly did you generate the matrices passed to TranformJ Affine create? 3) How did you create the 3D reconstruction of the planes? 4) How did you "rotate the 3D until the planes were parallel"? 5) How did you measure the angle between the plane? If your answer is lengthy, feel free to send it to me directly. Once we have an answer, we can post it back to the mailing list. -- David M. Gauntt, Ph.D. Associate Professor, Division of Medical Physics and Engineering UAB Department of Radiology mailto:[hidden email] 205-975-3777 On 2/17/12 1:18 AM, "Jeffery, Nathan" <[hidden email]> wrote: >Thanks again David, > >I used the euler angles just as a convenient way to define the arbitrary >planes in a test dataset > >I created a block of black (0) voxels (300x300x325). > >I then used TransfromJ affine create, rotate to generate the first plane >(rotate 217, 51, 4) and painted it white. I then revert back to the >original stack using the inverse transform and repeat the process for >plane 2 (18, 64, 227). I end up with a stack of images with two arbitrary >planes painted through it. > >Next I created a 3D reconstruction of the planes and rotated the 3D until >the planes were parallel in orthographic view (not perspective). I then >take the angle between the two planes which turns out to be exactly >90degrees (hadn¹t planned this!). > >Finally, I used Reorient3TP to find the planes again. The matrices are >the same as those generated by transfromJ affine create above and it >finds the planes perfectly. > >However, if I then plug these numbers into the calculation I get 84.58 >degrees not 90. > >What I am having trouble working out is why the transform matrices will >find the planes perfectly but will not calculate the correct angle? > >I have repeated process several times to check each stage. Also, I have >repeated for different planes and get the correct answer. > >Any ideas? > > >________________________________________ >From: ImageJ Interest Group [[hidden email]] on behalf of David M >Gauntt [[hidden email]] >Sent: 16 February 2012 21:00 >To: [hidden email] >Subject: Re: Reorient3TP & transformations > >I am not a fan of Euler angles, so I don't have much experience with them. > How do you know that these angles define planes 90deg apart? There are >multiple ways to define Euler angles, no two of which lead to the same >transformation. It may be that Reorient3TP may be using a different >definition than you are using. > >-- >David M. Gauntt, Ph.D. >Associate Professor, >Division of Medical Physics and Engineering >UAB Department of Radiology > >mailto:[hidden email] >205-975-3777 > > > > > > > >On 2/16/12 2:22 PM, "Jeffery, Nathan" <[hidden email]> wrote: > >>Thanks to David & Johannes, >> >>This leads us to the real problem. I thought I was doing it wrong, hence >>my original question. >> >>I have two test arbitary planes that I know are 90degrees apart. They >>were originally defined by euler angles - >>plane 1 = (217, 51, 4 degrees in x, y, z) >>plane 2 = (18, 64, 227 degrees in x, y, z) >> >>If I put these angles in the transformJ affine create rotate function, >>transformj generates the rotation matrices and finds the planes >>perfectly! >> >>If I then multiply by (0,0,1) I am left with: >>vector1 = -0.661124967 0.557054233 -0.502597611 >>vector2 = -0.808975604 -0.414414938 0.416915736 >> >>the acos of the dot product = 84.58082316 >> >>which is not 90 degrees! >> >>In 9/10 cases it calculates the correct angle. >> >>Any ideas/suggestions? >>best >>nathan >> >> >> >> >> >> >>---------------------------------------------------------- >>Dr. Nathan Jeffery >>Department of Musculoskeletal Biology >>Institute of Ageing & Chronic Disease >>University of Liverpool >>Sherrington Bld. >>Ashton Street >>Liverpool L69 3GE >> >>Office: 0151 794 5514 >>Fax: 0151 794 5517 >>e-mail: [hidden email] >>http://pcwww.liverpool.ac.uk/~njeffery/ >>------------------------------------------------------- >>________________________________________ >>From: ImageJ Interest Group [[hidden email]] on behalf of Johannes >>Schindelin [[hidden email]] >>Sent: 16 February 2012 19:27 >>To: [hidden email] >>Subject: Re: Reorient3TP & transformations >> >>Hi David, >> >>On Thu, 16 Feb 2012, David M Gauntt wrote: >> >>> Multiply the affine transform >>> (http://www.imagescience.org/meijering/software/transformj/affine.html) >>> for each output plane by the vector (0,0,1,0); >> >>Multiplying a matrix by (0 0 1 0)^T is tantamount to extracting the third >>column from the matrix. >> >>> this is the z-axis of the input stack. >> >>More precisely: it is the unit vector in the positive direction of the z >>axis, but I think it is the axis of the output stack. >> >>Ciao, >>Johannes |
Dear David,
Many thanks for the discussions - got me thinking as well and turns out the euler angles were defined in a 1x1x1 space whereas the block and test planes are in a 1x1x1> space (i.e. voxels were nonisotropic, stretched in the Z). Multiplying the rotation matrix by the ratios of pixel to slice thickness and then taking the dot product of the vector gets me to 90degrees. Works for my other tests as well. Many, many thanks for all your help. best nathan On 20/02/2012 15:11, David M Gauntt wrote: > Jeffrey, > > As I understand TransformJ Affine create, the input parameters are not > Euler angles but rather 3x3 matrices; I assume that you used the Euler > angles to create the matrices. I would trust the result of the > calculation based on matrices; it is the 90 degree result that I would > question. > > I may use this as an opportunity to learn better how to manipulate stacks. > > 1) What plugin did use use to make the original 300x300x325 block? > 2) How exactly did you generate the matrices passed to TranformJ Affine > create? > 3) How did you create the 3D reconstruction of the planes? > 4) How did you "rotate the 3D until the planes were parallel"? > 5) How did you measure the angle between the plane? > > If your answer is lengthy, feel free to send it to me directly. Once we > have an answer, we can post it back to the mailing list. > > -- > David M. Gauntt, Ph.D. > Associate Professor, > Division of Medical Physics and Engineering > UAB Department of Radiology > > mailto:[hidden email] > 205-975-3777 > > > > > > > > On 2/17/12 1:18 AM, "Jeffery, Nathan"<[hidden email]> wrote: > >> Thanks again David, >> >> I used the euler angles just as a convenient way to define the arbitrary >> planes in a test dataset >> >> I created a block of black (0) voxels (300x300x325). >> >> I then used TransfromJ affine create, rotate to generate the first plane >> (rotate 217, 51, 4) and painted it white. I then revert back to the >> original stack using the inverse transform and repeat the process for >> plane 2 (18, 64, 227). I end up with a stack of images with two arbitrary >> planes painted through it. >> >> Next I created a 3D reconstruction of the planes and rotated the 3D until >> the planes were parallel in orthographic view (not perspective). I then >> take the angle between the two planes which turns out to be exactly >> 90degrees (hadn¹t planned this!). >> >> Finally, I used Reorient3TP to find the planes again. The matrices are >> the same as those generated by transfromJ affine create above and it >> finds the planes perfectly. >> >> However, if I then plug these numbers into the calculation I get 84.58 >> degrees not 90. >> >> What I am having trouble working out is why the transform matrices will >> find the planes perfectly but will not calculate the correct angle? >> >> I have repeated process several times to check each stage. Also, I have >> repeated for different planes and get the correct answer. >> >> Any ideas? >> >> >> ________________________________________ >> From: ImageJ Interest Group [[hidden email]] on behalf of David M >> Gauntt [[hidden email]] >> Sent: 16 February 2012 21:00 >> To: [hidden email] >> Subject: Re: Reorient3TP& transformations >> >> I am not a fan of Euler angles, so I don't have much experience with them. >> How do you know that these angles define planes 90deg apart? There are >> multiple ways to define Euler angles, no two of which lead to the same >> transformation. It may be that Reorient3TP may be using a different >> definition than you are using. >> >> -- >> David M. Gauntt, Ph.D. >> Associate Professor, >> Division of Medical Physics and Engineering >> UAB Department of Radiology >> >> mailto:[hidden email] >> 205-975-3777 >> >> >> >> >> >> >> >> On 2/16/12 2:22 PM, "Jeffery, Nathan"<[hidden email]> wrote: >> >>> Thanks to David& Johannes, >>> >>> This leads us to the real problem. I thought I was doing it wrong, hence >>> my original question. >>> >>> I have two test arbitary planes that I know are 90degrees apart. They >>> were originally defined by euler angles - >>> plane 1 = (217, 51, 4 degrees in x, y, z) >>> plane 2 = (18, 64, 227 degrees in x, y, z) >>> >>> If I put these angles in the transformJ affine create rotate function, >>> transformj generates the rotation matrices and finds the planes >>> perfectly! >>> >>> If I then multiply by (0,0,1) I am left with: >>> vector1 = -0.661124967 0.557054233 -0.502597611 >>> vector2 = -0.808975604 -0.414414938 0.416915736 >>> >>> the acos of the dot product = 84.58082316 >>> >>> which is not 90 degrees! >>> >>> In 9/10 cases it calculates the correct angle. >>> >>> Any ideas/suggestions? >>> best >>> nathan >>> >>> >>> >>> >>> >>> >>> ---------------------------------------------------------- >>> Dr. Nathan Jeffery >>> Department of Musculoskeletal Biology >>> Institute of Ageing& Chronic Disease >>> University of Liverpool >>> Sherrington Bld. >>> Ashton Street >>> Liverpool L69 3GE >>> >>> Office: 0151 794 5514 >>> Fax: 0151 794 5517 >>> e-mail: [hidden email] >>> http://pcwww.liverpool.ac.uk/~njeffery/ >>> ------------------------------------------------------- >>> ________________________________________ >>> From: ImageJ Interest Group [[hidden email]] on behalf of Johannes >>> Schindelin [[hidden email]] >>> Sent: 16 February 2012 19:27 >>> To: [hidden email] >>> Subject: Re: Reorient3TP& transformations >>> >>> Hi David, >>> >>> On Thu, 16 Feb 2012, David M Gauntt wrote: >>> >>>> Multiply the affine transform >>>> (http://www.imagescience.org/meijering/software/transformj/affine.html) >>>> for each output plane by the vector (0,0,1,0); >>> Multiplying a matrix by (0 0 1 0)^T is tantamount to extracting the third >>> column from the matrix. >>> >>>> this is the z-axis of the input stack. >>> More precisely: it is the unit vector in the positive direction of the z >>> axis, but I think it is the axis of the output stack. >>> >>> Ciao, >>> Johannes -- ---------------------------------------------------------- Dr. Nathan Jeffery Department of Musculoskeletal Biology Institute of Ageing& Chronic Disease University of Liverpool Sherrington Bld. Ashton Street Liverpool L69 3GE Office: 0151 794 5514 Fax: 0151 794 5517 e-mail: [hidden email] http://pcwww.liverpool.ac.uk/~njeffery/ ------------------------------------------------------- |
Free forum by Nabble | Edit this page |