Coronal, Sagittal & Transverse position calculation

To calculate frame position in terms of Sagittal, Coronal and Transverse position please see the attached code.

 

{//*~get info from file~*//
 // (0028,0030)
 float[] pixel_space = new float[2];
 string[] pixel_space_p = Viewer.CurrentImage.DataSet[0x0028, 0x0030].Value as string[];
 pixel_space[0] = float.Parse(pixel_space_p[0]); //Pixel size (row to row) 
 pixel_space[1] = float.Parse(pixel_space_p[1]); //Pixel size (collom to collom)

 // (0028,0010) & (0028,0011)
 ushort rows = (ushort)(Viewer.CurrentImage.DataSet[0x0028, 0x0010].Value);      // number of rows
 ushort colums = (ushort)(Viewer.CurrentImage.DataSet[0x0028, 0x0011].Value);    // number of colloms

 // (0020,0032)           
 double[] top_left_corner = new double[3];
 string[] top_left_corner_p = Viewer.CurrentImage.DataSet[0x0020, 0x0032].Value as string[];
 top_left_corner[0] = double.Parse(top_left_corner_p[0]);            // X  pos of frame (Top left) in real space   
 top_left_corner[1] = double.Parse(top_left_corner_p[1]);            // Y
 top_left_corner[2] = double.Parse(top_left_corner_p[2]);            // Z

 // (0020,0037)
 double[,] frame_vec = new double[3, 3];
 string[] frame_vec_p = Viewer.CurrentImage.DataSet[0x0020, 0x0037].Value as string[];
 frame_vec[0, 0] = double.Parse(frame_vec_p[0]);                     //top edge frame vector x1
 frame_vec[0, 1] = double.Parse(frame_vec_p[1]);                     //top edge frame vector y1
 frame_vec[0, 2] = double.Parse(frame_vec_p[2]);                     //top edge frame vector z1
 frame_vec[1, 0] = double.Parse(frame_vec_p[3]);                     //left edge frame vector x1
 frame_vec[1, 1] = double.Parse(frame_vec_p[4]);                     //left edge frame vector y1
 frame_vec[1, 2] = double.Parse(frame_vec_p[5]);                     //left edge frame vector z1
 //  calculate the frame Normal the frame normal lets us know if the image is Sag, Tran or Coronal
 frame_vec[2, 0] = frame_vec[0, 1] * frame_vec[1, 2] - frame_vec[0, 2] * frame_vec[1, 1];
 frame_vec[2, 1] = frame_vec[0, 2] * frame_vec[1, 0] - frame_vec[0, 0] * frame_vec[1, 2];
 frame_vec[2, 2] = frame_vec[0, 0] * frame_vec[1, 1] - frame_vec[0, 1] * frame_vec[1, 0];
           
 //  calculate mid frame distance 
 double[] mid_frame = new double[3];
 mid_frame[0] = top_left_corner[0] + (colums / 2) * pixel_space[0] * frame_vec[0, 0] 
                                   + (rows / 2) * pixel_space[1] * frame_vec[1, 0];
 mid_frame[1] = top_left_corner[1] + (colums / 2) * pixel_space[0] * frame_vec[0, 1] 
                                   + (rows / 2) * pixel_space[1] * frame_vec[1, 1];
 mid_frame[2] = top_left_corner[2] + (colums / 2) * pixel_space[0] * frame_vec[0, 2] 
                                   + (rows / 2) * pixel_space[1] * frame_vec[1, 2];
 // if Sagittal check
 if ((Math.Abs(frame_vec[2,0]) > Math.Abs(frame_vec[2,1])) 
     && (Math.Abs(frame_vec[2,0]) > Math.Abs(frame_vec[2,2])))
 {   
    if (Math.Abs(frame_vec[2, 0]) < 0.99)
       MessageBox.Show("Sagittal (" + Convert.ToString(mid_frame[0]) + ")");
    else
       MessageBox.Show("Sagittal " + Convert.ToString(mid_frame[0]));
 }
 else //Cor check
 if ((Math.Abs(frame_vec[2, 1])  > Math.Abs(frame_vec[2, 0])) 
      && (Math.Abs(frame_vec[2, 1]) > Math.Abs(frame_vec[2, 2]))) 
 {
    if (Math.Abs(frame_vec[2, 1]) < 0.99)
       MessageBox.Show("Coronal (" + Convert.ToString(mid_frame[1]) + ")");
    else
       MessageBox.Show("Coronal " + Convert.ToString(mid_frame[1]));
 }
 else // Ax 
 {  if (Math.Abs(frame_vec[2, 2]) < 0.99)
       MessageBox.Show("Transverse (" + Convert.ToString(mid_frame[1]) + ")");
    else
       MessageBox.Show("Transverse " + Convert.ToString(mid_frame[1]));
 }
}
Relevance: