# Get each slice of a volume as numpy array

**URL:** <https://discourse.slicer.org/t/get-each-slice-of-a-volume-as-numpy-array/3986>\
**Category:** Development\
**Created:** [September 4, 2018, 5:44am UTC](https://discourse.slicer.org/t/get-each-slice-of-a-volume-as-numpy-array/3986 "2018-09-04T05:44:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [September 4, 2018, 5:44am UTC](https://discourse.slicer.org/t/get-each-slice-of-a-volume-as-numpy-array/3986/1 "2018-09-04T05:44:21Z")

</div>

Hi Andras,  
Would you please tell me how to split the volume into slices after having volume into numpy array?

What I need to do is to apply clustering FCM algorithm on volume to get classified volume. For which I am thinking in this way.  
Get the volume  
Split it into slices  
convert each slice into its respective numpy array  
passing numpy array of a slice to algorithm  
Getting the updated numpy array  
converting numpy back to slice of volume  
Then collectivly combining all the slices into volume

Thank you

Looking forward for your reply

---

<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:** [September 4, 2018, 6:43pm UTC](https://discourse.slicer.org/t/get-each-slice-of-a-volume-as-numpy-array/3986/2 "2018-09-04T18:43:04Z")

</div>

You can easily get a slice of a volume by standard numpy indexing of arrays. Here is an example: [https://gist.github.com/lassoan/d85be45b7284a3b4e580688fccdb1d02](https://gist.github.com/lassoan/d85be45b7284a3b4e580688fccdb1d02)

However, I would recommend to segment in 3D rather than arbitrarily splitting the volume to 2D pieces and re-assembling it.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [September 5, 2018, 2:28am UTC](https://discourse.slicer.org/t/get-each-slice-of-a-volume-as-numpy-array/3986/3 "2018-09-05T02:28:28Z")

</div>

Hi Andras,  
Thank you for suggesting. Please tell where should I start from if I want to do 3D segmentation.

Regards,  
Saima Safdar

---

<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:** [September 5, 2018, 3:32am UTC](https://discourse.slicer.org/t/get-each-slice-of-a-volume-as-numpy-array/3986/4 "2018-09-05T03:32:17Z")

</div>

What would you like to segment? On what imaging modality? For what clinical purpose?

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [September 5, 2018, 4:26am UTC](https://discourse.slicer.org/t/get-each-slice-of-a-volume-as-numpy-array/3986/5 "2018-09-05T04:26:02Z")

</div>

Hi,  
want to segment three parts brain, ventricles and tumor, MRI. automating the segmentation process and then using it for brain deformation calculation.
