# how to perform CBCT 3D reconstruction given a squence of 2D .raw X-ray images and corresponding projection matrices

**URL:** <https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251>\
**Category:** Beginner Questions\
**Tags:** itk\
**Created:** [October 10, 2024, 3:05am UTC](https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251 "2024-10-10T03:05:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhangxiang](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/c77e96/32.png) [@zhangxiang](https://discourse.itk.org/u/zhangxiang)\
**Post date:** [October 10, 2024, 3:05am UTC](https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251/1 "2024-10-10T03:05:05Z")

</div>

I want to do this work in The Reconstruction Toolkit, and I know how to use a .mha file to reconstruction. But i do not know how to store .raw image sequence into a .mha file(or multiple if possible) with correct origin and direction.  
In RTK 3D circular projection geometry ([http://www.openrtk.org/Doxygen/DocGeo3D.html](http://www.openrtk.org/Doxygen/DocGeo3D.html)), the v-axis of the physical coordinate system is opposite to the v-axis of the image.  
The size of X-ray image is 1408×1408, the pixelsize is 0.308. I want to set the origin of the physical coordinates at the center of the image.

How to set origin,direction? OR to recommend a tool that is better than RTK.

---

<div class="post-metadata">

**Author:** ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)\
**Post date:** [October 10, 2024, 12:44pm UTC](https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251/2 "2024-10-10T12:44:25Z")

</div>

In RTK, the stack of projection images is read as a 3D image (`itk::Image<float, 3>`). If you want to set the origin of the coordinate system at the center of the projection image, you need to set `itk::Image<float, 3>::m_Origin` (with `itk::Image<float, 3>::SetOrigin`) to -0.5\*(number of pixels -1)\* spacing, i.e. -0.5 \* 1407 \* 0.308=-216.678 for the first and second coordinates. The third coordinate is not used by RTK. The direction can be set to identity.

I don’t see why you think that “the v-axis of the physical coordinate system is opposite to the v-axis of the image”? This is not what the documentation drawing indicate at least.

I can try to help if you share your projection matrices and a set of data.

---

<div class="post-metadata">

**Author:** ![zhangxiang](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/c77e96/32.png) [@zhangxiang](https://discourse.itk.org/u/zhangxiang)\
**Post date:** [October 14, 2024, 1:56am UTC](https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251/3 "2024-10-14T01:56:25Z")

</div>

Thanks for your answer.  
In the RTK WIKI, [RTK: RTK 3D circular projection geometry](http://www.openrtk.org/Doxygen/DocGeo3D.html). 9 geometric parameters can determine a camera. In 2D image, u→,v↓ . But in this 3D circular geometry, u→, v↑. why?  
I can get projection matrice by using DLT and optimization. But in pinhole model, u→, v↓. can i input this kinds of projection matrice?

I really need your help. My email is [zx694040645@outlook.com](mailto:zx694040645@outlook.com)

---

<div class="post-metadata">

**Author:** ![zhangxiang](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/c77e96/32.png) [@zhangxiang](https://discourse.itk.org/u/zhangxiang)\
**Post date:** [October 14, 2024, 2:43am UTC](https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251/4 "2024-10-14T02:43:19Z")

</div>

Thanks for your answer.  
In the RTK WIKI, [RTK: RTK 3D circular projection geometry](http://www.openrtk.org/Doxygen/DocGeo3D.html). 9 geometric parameters can determine a camera. In 2D image, u→,v↓ . But in this 3D circular geometry, u→, v↑. why?  
I can get projection matrice by using DLT and optimization. But in pinhole model, u→, v↓. can i input this kinds of projection matrice?

I really need your help. My email is [zx694040645@outlook.com](mailto:zx694040645@outlook.com)

---

<div class="post-metadata">

**Author:** ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)\
**Post date:** [October 14, 2024, 4:45am UTC](https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251/5 "2024-10-14T04:45:56Z")

</div>

I believe you can describe any projection geometry, possibly with negative `SourceToDetectorDistance` and `SourceToIsocenterDistance`. If the only problem is the orientation of v, you can use a 180° `OutOfPlaneAngle`.

---

<div class="post-metadata">

**Author:** ![zhangxiang](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/c77e96/32.png) [@zhangxiang](https://discourse.itk.org/u/zhangxiang)\
**Post date:** [October 14, 2024, 7:48am UTC](https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251/6 "2024-10-14T07:48:03Z")

</div>

First of all, we set the origin at the center of X-ray image for convenience.

In 3D CIRCULAR PROJECTION GEOMETRY of RTK, the directions of u v is u→, v↑, seen in the picture.

 ![image](https://discourse.itk.org/uploads/default/original/2X/1/1a207103ea55eb3964250a52c882a4bb8e24f15f.jpeg)

The direction of uv of a 2D image in ITK is u→v↓ , like this:  
 ![image](https://discourse.itk.org/uploads/default/original/2X/5/50d7bd44ef793b2b138fb6e8a762b4ca865c17e7.png)

For a pinhole model and Direct linear transform, the model is like this :

 ![image](https://discourse.itk.org/uploads/default/original/2X/4/463b5ef9a35c6dc9f948f0b06cefa300343dac95.png).  
 ![image](https://discourse.itk.org/uploads/default/original/2X/8/8979a2ed3d3f539495e83fc827f15ff205200bbc.png)

The world coordinate system of pinhole model is different from 3DCIRCULARPROJECTIONGEOMETRY but this difference doesnt matter in this problem because I pre-process 3D points.

I got a Master’s degree in Pure Mathematics so that donot worry about my knowledge about 3D geometry. I can transform these parameter from two models (pinhole and RTK) and verified through simulation experiments.

According to my understanding, there are two methods using rtkfdk.exe:

1. input projection matrice from DLT, do not set --newdirection. (In this case, I always get a negative SID in XML.)  
 ![70a4c818fcdf50cb0ae37ef3d8c53c7f](https://discourse.itk.org/uploads/default/original/2X/1/16a08756cae6762b7406a5944d3385ddb258237f.png)  
|-245.552456178466|-1.32595721624889|-1519.50095868829|8164.02834122301|  
|—|—|—|—|  
|-11.6382782563406|-1539.16490184778|3.25659871589372|4847.29978914652|  
|-0.986422424313713|0.00336677752224844|0.164193378734263|1031.67061077634|

2. get projection matrice by DLT, transform DLT results to get 9 geometric parameters or M\_p in [RTK: RTK 3D circular projection geometry](http://www.openrtk.org/Doxygen/DocGeo3D.html), input 9 parameters or M\_p, set - newdirection 1 0 0, 0 -1 0, 0 0 1.

(tips: If the Y-axis of the world coordinates coincides with the rotation axis of CBCT system, the i-th gantry angle can be set 360°/imagenum\*(i-1), the other 8 parameters are the same for all images.)

I think the projection matrice of M\_p is different from the projection matrice obtained by DLT because the direction of v in these 2 models are different.

---

<div class="post-metadata">

**Author:** ![zhangxiang](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/c77e96/32.png) [@zhangxiang](https://discourse.itk.org/u/zhangxiang)\
**Post date:** [October 14, 2024, 7:51am UTC](https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251/7 "2024-10-14T07:51:41Z")

</div>

First of all, we set the origin at the center of X-ray image for convenience.

In 3D CIRCULAR PROJECTION GEOMETRY of RTK, the directions of u v is u→, v↑, seen in the picture.

 ![image](https://discourse.itk.org/uploads/default/original/2X/1/1a207103ea55eb3964250a52c882a4bb8e24f15f.jpeg)

The direction of uv of a 2D image in ITK is u→v↓ , like this:  
 ![image](https://discourse.itk.org/uploads/default/original/2X/5/50d7bd44ef793b2b138fb6e8a762b4ca865c17e7.png)

For a pinhole model and Direct linear transform, the model is like this :

 ![image](https://discourse.itk.org/uploads/default/original/2X/4/463b5ef9a35c6dc9f948f0b06cefa300343dac95.png)

.

 ![image](https://discourse.itk.org/uploads/default/original/2X/8/8979a2ed3d3f539495e83fc827f15ff205200bbc.png)

The world coordinate system of pinhole model is different from 3DCIRCULARPROJECTIONGEOMETRY but this difference doesnt matter in this problem because I pre-process 3D points.

I got a Master’s degree in Pure Mathematics so that donot worry about my knowledge about 3D geometry. I can transform these parameter from two models (pinhole and RTK) and verified through simulation experiments.

According to my understanding, there are two methods using rtkfdk.exe:

1. input projection matrice from DLT, do not set --newdirection. (In this case, I always get a negative SID in XML.)  
 ![70a4c818fcdf50cb0ae37ef3d8c53c7f](https://discourse.itk.org/uploads/default/original/2X/1/16a08756cae6762b7406a5944d3385ddb258237f.png)  
|-245.552456178466|-1.32595721624889|-1519.50095868829|8164.02834122301|  
|—|—|—|—|  
|-11.6382782563406|-1539.16490184778|3.25659871589372|4847.29978914652|  
|-0.986422424313713|0.00336677752224844|0.164193378734263|1031.67061077634|
2. get projection matrice by DLT, transform DLT results to get 9 geometric parameters or M\_p in [RTK: RTK 3D circular projection geometry](http://www.openrtk.org/Doxygen/DocGeo3D.html), input 9 parameters or M\_p, set - newdirection 1 0 0, 0 -1 0, 0 0 1.

(tips: If the Y-axis of the world coordinates coincides with the rotation axis of CBCT system, the i-th gantry angle can be set 360°/imagenum\*(i-1), the other 8 parameters are the same for all images.)

I think the projection matrice of M\_p is different from the projection matrice obtained by DLT because the direction of v in these 2 models are different.  
[/quote]

---

<div class="post-metadata">

**Author:** ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)\
**Post date:** [October 14, 2024, 8:06am UTC](https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251/8 "2024-10-14T08:06:43Z")

</div>

Thanks for the report. Are you actually able to achieve what you want now?

---

<div class="post-metadata">

**Author:** ![zhangxiang](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/c77e96/32.png) [@zhangxiang](https://discourse.itk.org/u/zhangxiang)\
**Post date:** [October 14, 2024, 9:00am UTC](https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251/9 "2024-10-14T09:00:45Z")

</div>

I cannot input .raw image on my computer, I now search for a method to transform .raw into .dcm or .mha. IMAGEJ and XMEDCON cannot work.

---

<div class="post-metadata">

**Author:** ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)\
**Post date:** [October 14, 2024, 9:10am UTC](https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251/10 "2024-10-14T09:10:04Z")

</div>

You simply have to write a .mhd header file. There are several solutions to do this, one is in Python, read in the raw file with numpy and convert it with the `itk.image_from_array` function.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [October 14, 2024, 1:01pm UTC](https://discourse.itk.org/t/how-to-perform-cbct-3d-reconstruction-given-a-squence-of-2d-raw-x-ray-images-and-corresponding-projection-matrices/7251/11 "2024-10-14T13:01:08Z")

</div>

You can also write `.mhd` header file by hand. Instructions are in [MetaImage documentation](https://itk.org/Wiki/ITK/MetaIO/Documentation#Reading_a_Brick-of-Bytes_(an_N-Dimensional_volume_in_a_single_file)).
