# Rotation of a CT image around the RT isocenter, in python

**URL:** https://discourse.slicer.org/t/rotation-of-a-ct-image-around-the-rt-isocenter-in-python/3203
**Category:** Support
**Tags:** dicom, transforms, python
**Created:** [June 16, 2018, 6:50am UTC](https://discourse.slicer.org/t/rotation-of-a-ct-image-around-the-rt-isocenter-in-python/3203 "2018-06-16T06:50:13Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![gdenunzio](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gdenunzio](https://discourse.slicer.org/u/gdenunzio)
#### Post date: [June 16, 2018, 6:50am UTC](https://discourse.slicer.org/t/rotation-of-a-ct-image-around-the-rt-isocenter-in-python/3203/1 "2018-06-16T06:50:13Z")

</div>

Hi all,  
I am a 3D Slicer beginner, so please bear with me…

I have a CT image (in DICOM series format) used for radiation treatment planning. I wish to  
read it, apply to it an arbitrary 3D rotation around the isocenter, then resave it as a DICOM series (to read it back into the TPS).  
I wish to do it by python scripting (because I’ll have many different rotations to explore, so I want to automate the procedure).  
I am learning by doing, because at present I don’t have much time to fully understand the software before starting coding.

By reading what I coud find in the Forum and in the documentation, I understood how to:

1. prepare things:

2. parse the command line:

3. read the dicom series:

4. Save as nnrd, which is not what I need, but it was at least a test that I was correctly reading the image and filling the right Slicer structures…

5. Get out:

except Exception, e:  
print e  
sys.exit()  
return

1. Prepare “main” execution:

My questions are:

1. How do I apply the rotation transform?

2. I imagine I can apply a chain of transforms, so I can translate the image so that the isocenter is in the axis origin, then rotate, than translate back: how to do it?

3. How do I save the result as a DICOM series, by using the input DICOM series as a model (as to voxel/slice dimensions, and all the other relevant DICOM fields)?

Any hint, code snippets, link to relevant material, is really welcome.  
Thank you very much.  
Giorgio  
PS sorry, after many tries, I am not succeeding in correctly formatting the code snippets… preformatted text does not give the desired result… indentation has totally gone…

---

<div class="post-metadata">

### Author: ![gdenunzio](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gdenunzio](https://discourse.slicer.org/u/gdenunzio)
#### Post date: [June 16, 2018, 2:06pm UTC](https://discourse.slicer.org/t/rotation-of-a-ct-image-around-the-rt-isocenter-in-python/3203/2 "2018-06-16T14:06:44Z")

</div>

Beginning to see something.  
I applied some transformations this way:

```
vTransform = vtk.vtkTransform()
vTransform.Translate(-0.88, 35.4, 5.65) # translate by -isocenter
vTransform.Scale(1,1,1)
vTransform.RotateX(30) # The angle is in degrees
vTransform.Translate(0.88, -35.4, -5.65)
imageNode.ApplyTransform(vTransform)

```

Now I have to interpret what I am seing, and check if this is what I am looking for…  
Any help or comment are still very very welcome…!  
Best  
Giorgio

---

<div class="post-metadata">

### Author: ![Tiberiu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tiberiu/32/66666_2.png) [@Tiberiu](https://discourse.slicer.org/u/Tiberiu)
#### Post date: [June 13, 2023, 9:31am UTC](https://discourse.slicer.org/t/rotation-of-a-ct-image-around-the-rt-isocenter-in-python/3203/3 "2023-06-13T09:31:09Z")

</div>

Hi,  
I need to do the same as you. Do you know how to save the transformed scan? When I save the nrrd file for multiple rotations I get the same (presumably original) scan.

---

<div class="post-metadata">

### Author: ![ma1282029525](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ma1282029525/32/66047_2.png) [@ma1282029525](https://discourse.slicer.org/u/ma1282029525)
#### Post date: [June 14, 2023, 6:02am UTC](https://discourse.slicer.org/t/rotation-of-a-ct-image-around-the-rt-isocenter-in-python/3203/4 "2023-06-14T06:02:34Z")

</div>

The rotation operation you performed only involves visual effects, while the actual DICOM image does not undergo any transformation. In ITK, this requires resampling to complete

---

<div class="post-metadata">

### Author: ![KHhh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/khhh/32/67998_2.png) [@KHhh](https://discourse.slicer.org/u/KHhh)
#### Post date: [October 24, 2023, 5:28pm UTC](https://discourse.slicer.org/t/rotation-of-a-ct-image-around-the-rt-isocenter-in-python/3203/5 "2023-10-24T17:28:41Z")

</div>

Hey! I have been doing the same thing but instead of coding it using 3D slicer, I rotated the DCOM file using simpleITK, saved it as a nifti and have been using 3D slicer to view/ check my rotation was accurate. I think it works

---

<div class="post-metadata">

### Author: ![gdenunzio](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gdenunzio](https://discourse.slicer.org/u/gdenunzio)
#### Post date: [October 24, 2023, 5:37pm UTC](https://discourse.slicer.org/t/rotation-of-a-ct-image-around-the-rt-isocenter-in-python/3203/6 "2023-10-24T17:37:32Z")

</div>

Dear friends, before all thanks for your kind replies! Because of the long time elapsed, I had not realized that you had kindly replied! So excuse me and again thanks! I do not even remember if I solved somehow or if I gave up or used other tools (e.g. matlab). That said, thanks for your effort! Giorgio
