# How to split one segment into three equal parts via script?

**URL:** <https://discourse.slicer.org/t/how-to-split-one-segment-into-three-equal-parts-via-script/11287>\
**Category:** Support\
**Tags:** segmentation, python\
**Created:** [April 24, 2020, 12:23pm UTC](https://discourse.slicer.org/t/how-to-split-one-segment-into-three-equal-parts-via-script/11287 "2020-04-24T12:23:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ezio\_Lanza](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ezio_lanza/32/6285_2.png) [@Ezio\_Lanza](https://discourse.slicer.org/u/Ezio_Lanza)\
**Post date:** [April 24, 2020, 12:23pm UTC](https://discourse.slicer.org/t/how-to-split-one-segment-into-three-equal-parts-via-script/11287/1 "2020-04-24T12:23:57Z")

</div>

Hi,  
I need to create a script that splits one segment (e.g. volume lung) into three equal parts to simulate the three different lung lobes. (upper, mid and lower part).

Is there a good example to start or can you provide advice on the key commands to use?

Thanks

---

<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:** [April 24, 2020, 4:05pm UTC](https://discourse.slicer.org/t/how-to-split-one-segment-into-three-equal-parts-via-script/11287/2 "2020-04-24T16:05:19Z")

</div>

If you want to split to three equal volumes then you can use the new [Segment cross-section area extension](https://discourse.slicer.org/t/new-module-for-measuring-cross-section-area-of-segments/11293) to compute cross-sections along slices. You can get the positions as a table and get physical position of 0, 1/3, 2/3, full volume like this:

```python
crossSectionsTable = getNode('Segment cross-section area table')
positions = slicer.util.arrayFromTableColumn(crossSectionsTable, 'Position')
areas = slicer.util.arrayFromTableColumn(crossSectionsTable, 'Segment_1')

import numpy as np
volumeRatio = np.cumsum(areas)/np.sum(areas)
slicePositions = np.interp([0.0, 1.0/3.0, 2.0/3.0, 1.0], volumeRatio, positions[:,3])
print("Slice position along IS axis for zero, 1/3, 2/3, and full volumes: "+str(slicePositions))

```
