# Rotating and resampling volumes with Python

**URL:** <https://discourse.slicer.org/t/rotating-and-resampling-volumes-with-python/9089>\
**Category:** Support\
**Created:** [November 8, 2019, 5:31pm UTC](https://discourse.slicer.org/t/rotating-and-resampling-volumes-with-python/9089 "2019-11-08T17:31:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prashant\_Pandey](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@Prashant\_Pandey](https://discourse.slicer.org/u/Prashant_Pandey)\
**Post date:** [November 8, 2019, 5:31pm UTC](https://discourse.slicer.org/t/rotating-and-resampling-volumes-with-python/9089/1 "2019-11-08T17:31:34Z")

</div>

I’ve written a very simple python scrited module which sums a CT image’s along one of the 3 given axes to create a DRR-like image. However I want to extend this module to sum along an abitrary axis through the image instead of only the orthogonal directions.

I think the best way to approach this would be to use one of the resample image modules? Is there a better way of doing this - perhaps directly in numpy instead of borrowing another module’s logic? Thanks!

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [November 8, 2019, 6:16pm UTC](https://discourse.slicer.org/t/rotating-and-resampling-volumes-with-python/9089/2 "2019-11-08T18:16:49Z")

</div>

Probably the easiest is to apply a transform to the volume (rotation) and then resample using `Resample Image (brains)` as a CLI from python. Probably put it in a new volume so you can repeat with arbitrary directions.

---

<div class="post-metadata">

**Author:** ![haruki.9direction.ne](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/haruki.9direction.ne/32/66909_2.png) [@haruki.9direction.ne](https://discourse.slicer.org/u/haruki.9direction.ne)\
**Post date:** [July 21, 2023, 6:43am UTC](https://discourse.slicer.org/t/rotating-and-resampling-volumes-with-python/9089/3 "2023-07-21T06:43:35Z")

</div>

I rotated the mr image using a rotation matrix.  
How can the voxel resolution or size be recalculated in this process?  
Thank you

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 21, 2023, 2:02pm UTC](https://discourse.slicer.org/t/rotating-and-resampling-volumes-with-python/9089/4 "2023-07-21T14:02:42Z")

</div>

This example [script for extracting oriented boxes from a volume](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#extracting-volume-patches-around-segments) should help (maybe it does exactly what you want).
