Math behind IJK to RAS to convert Fiducial manually

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Math behind IJK to RAS to convert Fiducial manually

brhoom
This post has NOT been accepted by the mailing list yet.
Dear All,
I am trying to understand these by applying a simple example and I hope you can help with this. I already searched this mailing list and found some info but still I am confused.
Assume I have a Fiducial point F and an image with the following inputs:
O: Image Origin
S: Image Spacing
D: IJK to RAS Direction Matrix
F has different values than the values appear in the data probe as world coordinates W and pixel coordinates P (see the values below).
The question is how to convert between F, P and W. I tried different calculations but I didn't get correct results e.g: P= (W-O) / (D* S)

Here are the actual values from Slicer:
O = [1.5317756469822 75.4909583245956 -14.7028594538171]
S = [0.234375 0.234375 0.499999];
D =[ -0.9972    0.0317    -0.0672 ;
        -0.0355   -0.9978     0.0568;
        -0.0653    0.059       0.9961] ;
P =  [ 143      311        9 ];
F =  [ -29.9     2.64    -8.29 ];
W = [  29.8     1.8      8.3 ];

I appreciate your help,
Have a nice evening!
Ibraheem
Reply | Threaded
Open this post in threaded view
|

Math behind IJK to RAS to convert Fiducial manually

brhoom
Dear All, 
I am trying to understand these by applying a simple example and I hope you can help with this. I already searched this mailing list and found some info but still I am confused. 
Assume I have a Fiducial point F and an image with the following inputs: 
O: Image Origin 
S: Image Spacing 
D: IJK to RAS Direction Matrix 
F has different values than the values appear in the data probe as world coordinates W and pixel coordinates P (see the values below). 
The question is how to convert between F, P and W. I tried different calculations but I didn't get correct results e.g: P= (W-O) / (D* S) 

Here are the actual values from Slicer: 
O = [1.5317756469822 75.4909583245956 -14.7028594538171] 
S = [0.234375 0.234375 0.499999]; 
D =[ -0.9972    0.0317    -0.0672 ; 
        -0.0355   -0.9978     0.0568; 
        -0.0653    0.059       0.9961] ; 
P =  [ 143      311        9 ]; 
F =  [ -29.9     2.64    -8.29 ]; 
W = [  29.8     1.8      8.3 ]; 

I appreciate your help, 
Have a nice evening! 
Ibraheem
 

_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Math behind IJK to RAS to convert Fiducial manually

Tamas Ungi-2

Hi Ibraheem,

 

Here is an example how to find IJK coordinates of RAS coordinates. You an run this code if you download the MRHead sample data first:

 

v = slicer.util.getNode('MRHead')

RasToIjkMatrix = vtk.vtkMatrix4x4()

v.GetRASToIJKMatrix(RasToIjkMatrix)

p_Ras = [-1.597, -7.946, -10.214, 1]

p_Ijk = RasToIjkMatrix.MultiplyDoublePoint(p_Ras)

print p_Ijk

 

p_Ijk will be type double, so you need to round the numbers to get integer IJK coordinates.

 

Tamas

 

 

From: slicer-users [mailto:[hidden email]] On Behalf Of ibraheem aldhamari
Sent: November 10, 2016 4:35 PM
To: SPL Slicer Users <[hidden email]>
Subject: [slicer-users] Math behind IJK to RAS to convert Fiducial manually

 

Dear All, 
I am trying to understand these by applying a simple example and I hope you can help with this. I already searched this mailing list and found some info but still I am confused. 
Assume I have a Fiducial point F and an image with the following inputs: 
O: Image Origin 
S: Image Spacing 
D: IJK to RAS Direction Matrix 
F has different values than the values appear in the data probe as world coordinates W and pixel coordinates P (see the values below). 
The question is how to convert between F, P and W. I tried different calculations but I didn't get correct results e.g: P= (W-O) / (D* S) 

Here are the actual values from Slicer: 
O = [1.5317756469822 75.4909583245956 -14.7028594538171] 
S = [0.234375 0.234375 0.499999]; 
D =[ -0.9972    0.0317    -0.0672 ; 
        -0.0355   -0.9978     0.0568; 
        -0.0653    0.059       0.9961] ; 
P =  [ 143      311        9 ]; 
F =  [ -29.9     2.64    -8.29 ]; 
W = [  29.8     1.8      8.3 ]; 

I appreciate your help, 
Have a nice evening! 
Ibraheem

 


_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Math behind IJK to RAS to convert Fiducial manually

brhoom
This post was updated on .
In reply to this post by brhoom
Hi Tamas,
many thanks for your quick response. What I needed is to understand the code of GetRASToIJKMatrix. From what I saw, it just multiples the Spacing then put the Origin  in the last column, I think I am missing something or maybe I am reading the wrong code, see bellow.
One more thing: When I check it manually, for the point p_Ijk   =  [142 , 126 , 65 ] the p_Ras   =  [-2.350  , -8.207 , -9.214] which is not exactly the same as the input p_Ras   = [-1.597, -7.946, -10.214], There is about 1mm error ( I think it comes from the floating point ) is this acceptable and normal?
what about these values (I don't know what they call or what they represent) we see in the DataProbe? how can I convert them to p_Ijk?
e.g. for   p_Ras   =  [-2.247  , -8.034,-9.214] I got p_???= [2.3, 8.1, 9.2] (see the image here: https://drive.google.com/open?id=0B6CYc5oVUOLSTzhVQXRlNXFZYlU)

Have a nice day!
Ibraheem

From: vtkMRMLVolumeNode.cxx
Void vtkMRMLVolumeNode::GetIJKToRASMatrix(vtkMatrix4x4* mat)
{

// this is the full matrix including the spacing and origin

mat->Identity();

int row, col;

for (row=0; row<3; row++)

  {

  for (col=0; col<3; col++)

    {

    mat->SetElement(row, col, this->Spacing[col] * IJKToRASDirections[row][col]);

    }

  mat->SetElement(row, 3, this->Origin[row]);

  }

}



//----------------------------------------------------------------------------

void vtkMRMLVolumeNode::GetRASToIJKMatrix(vtkMatrix4x4* mat)

{

this->GetIJKToRASMatrix( mat );

mat->Invert();

}

________________________________
From: Tamas Ungi <ungi@queensu.ca>
To: ibraheem aldhamari <ibr_ex@yahoo.com>; SPL Slicer Users <slicer-users@bwh.harvard.edu>
Sent: Friday, November 11, 2016 1:34 AM
Subject: RE: Math behind IJK to RAS to convert Fiducial manually

Hi Ibraheem,

Here is an example how to find IJK coordinates of RAS coordinates. You an run this code if you download the MRHead sample data first:

v = slicer.util.getNode('MRHead')
RasToIjkMatrix = vtk.vtkMatrix4x4()
v.GetRASToIJKMatrix(RasToIjkMatrix)
p_Ras = [-1.597, -7.946, -10.214, 1]
p_Ijk = RasToIjkMatrix.MultiplyDoublePoint(p_Ras)
print p_Ijk

p_Ijk will be type double, so you need to round the numbers to get integer IJK coordinates.

Tamas


From: slicer-users [mailto:slicer-users-bounces@bwh.harvard.edu] On Behalf Of ibraheem aldhamari
Sent: November 10, 2016 4:35 PM
To: SPL Slicer Users <slicer-users@bwh.harvard.edu>
Subject: [slicer-users] Math behind IJK to RAS to convert Fiducial manually

Dear All,
I am trying to understand these by applying a simple example and I hope you can help with this. I already searched this mailing list and found some info but still I am confused.
Assume I have a Fiducial point F and an image with the following inputs:
O: Image Origin
S: Image Spacing
D: IJK to RAS Direction Matrix
F has different values than the values appear in the data probe as world coordinates W and pixel coordinates P (see the values below).
The question is how to convert between F, P and W. I tried different calculations but I didn't get correct results e.g: P= (W-O) / (D* S)

Here are the actual values from Slicer:
O = [1.5317756469822 75.4909583245956 -14.7028594538171]
S = [0.234375 0.234375 0.499999];
D =[ -0.9972    0.0317    -0.0672 ;
        -0.0355   -0.9978     0.0568;
        -0.0653    0.059       0.9961] ;
P =  [ 143      311        9 ];
F =  [ -29.9     2.64    -8.29 ];
W = [  29.8     1.8      8.3 ];

I appreciate your help,
Have a nice evening!
Ibraheem




_______________________________________________
slicer-users mailing list
slicer-users@bwh.harvard.edu
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to slicer-users-request@bwh.harvard.edu with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Math behind IJK to RAS to convert Fiducial manually

Andras Lasso-2

L-left

R-right

 

P-posterior

A-anterior

 

S-superior

I-inferior

 

For users it’s more meaningful to show a coordinate as L 15 (it’s on the left side) than R -15 (it’s not on the right side).

 

Andras

 

From: [hidden email]
Sent: Friday, November 11, 2016 6:17
To: [hidden email]; [hidden email]
Subject: Re: [slicer-users] Math behind IJK to RAS to convert Fiducial manually

 

Hi Tamas,
many thanks for your quick response. What I needed is to understand the code of GetRASToIJKMatrix. From what I saw, it just multiples the Spacing then put the Origin  in the last column, I think I am missing something or maybe I am reading the wrong code, see bellow.  
One more thing: When I check it manually, for the point p_Ijk   =  [142 , 126 , 65 ] the p_Ras   =  [-2.350  , -8.207 , -9.214] which is not exactly the same as the input p_Ras   = [-1.597, -7.946, -10.214], There is about 1mm error ( I think it comes from the floating point ) is this acceptable and normal?
what about these values (I don't know what they call or what they represent) we see in the DataProbe? how can I convert them to p_Ijk? 
e.g. for   p_Ras   =  [-2.247  , -8.034,-9.214] I got p_???= [2.3, 8.1, 9.2] (see the image here: https://drive.google.com/open?id=0B6CYc5oVUOLSTzhVQXRlNXFZYlU)

Have a nice day!
Ibraheem

From: vtkMRMLVolumeNode.cxx
Void vtkMRMLVolumeNode::GetIJKToRASMatrix(vtkMatrix4x4* mat)
{
// this is the full matrix including the spacing and origin
mat->Identity();
int row, col;
for (row=0; row<3; row++)
  {
  for (col=0; col<3; col++)
    {
    mat->SetElement(row, col, this->Spacing[col] * IJKToRASDirections[row][col]);
    }
  mat->SetElement(row, 3, this->Origin[row]);
  }
}

//----------------------------------------------------------------------------
void vtkMRMLVolumeNode::GetRASToIJKMatrix(vtkMatrix4x4* mat)
{
this->GetIJKToRASMatrix( mat );
mat->Invert();
}

From: Tamas Ungi <[hidden email]>
To: ibraheem aldhamari <[hidden email]>; SPL Slicer Users <[hidden email]>
Sent: Friday, November 11, 2016 1:34 AM
Subject: RE: Math behind IJK to RAS to convert Fiducial manually

Hi Ibraheem,
 
Here is an example how to find IJK coordinates of RAS coordinates. You an run this code if you download the MRHead sample data first:
 
v = slicer.util.getNode('MRHead')
RasToIjkMatrix = vtk.vtkMatrix4x4()
v.GetRASToIJKMatrix(RasToIjkMatrix)
p_Ras = [-1.597, -7.946, -10.214, 1]
p_Ijk = RasToIjkMatrix.MultiplyDoublePoint(p_Ras)
print p_Ijk
 
p_Ijk will be type double, so you need to round the numbers to get integer IJK coordinates.
 
Tamas
 
From: slicer-users [mailto:[hidden email]] On Behalf Of ibraheem aldhamari
Sent: November 10, 2016 4:35 PM
To: SPL Slicer Users <[hidden email]>
Subject: [slicer-users] Math behind IJK to RAS to convert Fiducial manually
 
Dear All, 
I am trying to understand these by applying a simple example and I hope you can help with this. I already searched this mailing list and found some info but still I am confused. 
Assume I have a Fiducial point F and an image with the following inputs: 
O: Image Origin 
S: Image Spacing 
D: IJK to RAS Direction Matrix 
F has different values than the values appear in the data probe as world coordinates W and pixel coordinates P (see the values below). 
The question is how to convert between F, P and W. I tried different calculations but I didn't get correct results e.g: P= (W-O) / (D* S) 

Here are the actual values from Slicer: 
O = [1.5317756469822 75.4909583245956 -14.7028594538171] 
S = [0.234375 0.234375 0.499999]; 
D =[ -0.9972    0.0317    -0.0672 ; 
        -0.0355   -0.9978     0.0568; 
        -0.0653    0.059       0.9961] ; 
P =  [ 143      311        9 ]; 
F =  [ -29.9     2.64    -8.29 ]; 
W = [  29.8     1.8      8.3 ]; 

I appreciate your help, 
Have a nice evening! 
Ibraheem
 



_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Math behind IJK to RAS to convert Fiducial manually

brhoom
Thanks a lot, I think I got it now



--
View this message in context: http://slicer-users.65878.n3.nabble.com/Math-behind-IJK-to-RAS-to-convert-Fiducial-manually-tp4031282p4031327.html
Sent from the slicer-users mailing list archive at Nabble.com.
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Math behind IJK to RAS to convert Fiducial manually

brhoom
This post has NOT been accepted by the mailing list yet.
In reply to this post by Andras Lasso-2
Thanks a lot, I think I got it now