# Positioning of CT volume for DRR generation

**URL:** <https://discourse.itk.org/t/positioning-of-ct-volume-for-drr-generation/6133>\
**Category:** Beginner Questions\
**Tags:** itk, dicom, python\
**Created:** [August 9, 2023, 6:21pm UTC](https://discourse.itk.org/t/positioning-of-ct-volume-for-drr-generation/6133 "2023-08-09T18:21:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vojtech\_Benda](https://discourse.itk.org/user_avatar/discourse.itk.org/vojtech_benda/32/3623_2.png) [@Vojtech\_Benda](https://discourse.itk.org/u/Vojtech_Benda)\
**Post date:** [August 9, 2023, 6:21pm UTC](https://discourse.itk.org/t/positioning-of-ct-volume-for-drr-generation/6133/1 "2023-08-09T18:21:22Z")

</div>

Hello, I’m trying to generate DRR images from CT slices at certain angles (0°, 45°, 90°…). I’m using this C++ [DRR example](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Examples/Filtering/DigitallyReconstructedRadiograph1.cxx) rewrote in Python: [https://github.com/Vojtech-Benda/DRR\_generation/blob/main/drrGen.py](https://github.com/Vojtech-Benda/DRR_generation/blob/main/drrGen.py)

I managed to get a reasonable result for AP view (0° rotation around z-axis (head to feet)), however I feel like one or more geometry parameters are wrong (volume center and origin, output image origin etc.).

 ![drr_image3](https://discourse.itk.org/uploads/default/original/2X/4/4224cfbea5528a2213c24f90bf7b99e6c5090e4e.png)

Also, changing the rotation around z-axis moves the CT volume outside x-ray source’s “view”, which is most likely caused by the transformation’s center not being in the volume’s center.

 ![drr_image2](https://discourse.itk.org/uploads/default/original/2X/e/e97622a4fc326e160c7fd5ab774703d0f648418c.png)

I tried changing various parameters with similar or no results. Following on that, can I choose arbitrary size of the output DRR image or is it dependent on the distances between x-ray source, CT volume and its size and output image.

Thanks in advance.

---

<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:** [August 10, 2023, 1:13pm UTC](https://discourse.itk.org/t/positioning-of-ct-volume-for-drr-generation/6133/2 "2023-08-10T13:13:37Z")

</div>

@simon.rit might have some advice.

---

<div class="post-metadata">

**Author:** ![Vojtech\_Benda](https://discourse.itk.org/user_avatar/discourse.itk.org/vojtech_benda/32/3623_2.png) [@Vojtech\_Benda](https://discourse.itk.org/u/Vojtech_Benda)\
**Post date:** [August 10, 2023, 2:25pm UTC](https://discourse.itk.org/t/positioning-of-ct-volume-for-drr-generation/6133/3 "2023-08-10T14:25:02Z")

</div>

I believe I fixed the issue. The transformation’s center of rotation and input CT volume’s origin was set to the same location, causing the above misalignment. Removing the line that sets input volume’s origin fixes it. I’ve updated [drrGen.py](https://github.com/Vojtech-Benda/DRR_generation/blob/main/drrGen.py) for anyone with similar problem.

 ![drr_image1](https://discourse.itk.org/uploads/default/original/2X/0/09b8aa5f288a09eb4aca822f2034a475e9f096eb.png)  
 ![drr_image2](https://discourse.itk.org/uploads/default/original/2X/e/eb4321c202ab966423a638fefc2208bcdee2fe46.png)  
 ![drr_image3](https://discourse.itk.org/uploads/default/original/2X/4/4db302661bd6459e12a34cec9505be6773f04698.png)

I also found out that changing the size of output DRR image enlarges/shrinks the result, technically padding or cropping the image. I believe getting the correct size should be a simple trigonometry task, provided both source to detector and source to patient are known.
