# Tumor segmentation

**URL:** <https://discourse.slicer.org/t/tumor-segmentation/2211>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [February 28, 2018, 6:19pm UTC](https://discourse.slicer.org/t/tumor-segmentation/2211 "2018-02-28T18:19:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nodi](https://avatars.discourse-cdn.com/v4/letter/n/57b2e6/32.png) [@nodi](https://discourse.slicer.org/u/nodi)\
**Post date:** [February 28, 2018, 6:19pm UTC](https://discourse.slicer.org/t/tumor-segmentation/2211/1 "2018-02-28T18:19:58Z")

</div>

I tried to segment the tumor but when I save it as .nrrd, I got the whole volume with other tissues. I want to save and use JUST the tumor volume. how can I do that?

Do I have to use the Editor to segment the tumor or I can do something by CLI?

---

<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:** [February 28, 2018, 7:37pm UTC](https://discourse.slicer.org/t/tumor-segmentation/2211/2 "2018-02-28T19:37:01Z")

</div>

Hide all segments that you don’t want to export and in advanced section of Export section, choose Visible segments only.

---

<div class="post-metadata">

**Author:** ![nodi](https://avatars.discourse-cdn.com/v4/letter/n/57b2e6/32.png) [@nodi](https://discourse.slicer.org/u/nodi)\
**Post date:** [March 1, 2018, 12:18am UTC](https://discourse.slicer.org/t/tumor-segmentation/2211/3 "2018-03-01T00:18:27Z")

</div>

Thank you it works and I got (segmentation.seg.nrrd and segmentation-lable.nrrd)

However, since I’m new learner, I want to get the volume (segmented tumor) as an array.

so I loaded the “segmentation-lable.nrrd” then:

> > > o= slicer.util.array(‘segmentation-lable’)  
> > > print (o)  
> > > [[[0 0 0 …, 0 0 0]  
> > > [0 0 0 …, 0 0 0]  
> > > [0 0 0 …, 0 0 0]  
> > > …

I’m getting zeros  
Could you please guide me

Thank you.

---

<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:** [March 1, 2018, 1:08am UTC](https://discourse.slicer.org/t/tumor-segmentation/2211/4 "2018-03-01T01:08:14Z")

</div>

It may look like zeros, but your data is probably just being shortened for display.

Try `o.max()` and you should see the label value you exported.

Also something like:

```auto
import numpy
numpy.transpose(numpy.where(o==1))

```

will give you a list of the pixel coordinates where there’s a 1 in the segmentation array.

HTH

---

<div class="post-metadata">

**Author:** ![nodi](https://avatars.discourse-cdn.com/v4/letter/n/57b2e6/32.png) [@nodi](https://discourse.slicer.org/u/nodi)\
**Post date:** [March 1, 2018, 1:24am UTC](https://discourse.slicer.org/t/tumor-segmentation/2211/5 "2018-03-01T01:24:26Z")

</div>

now I got “None” when printing o

---

<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:** [March 1, 2018, 2:26am UTC](https://discourse.slicer.org/t/tumor-segmentation/2211/6 "2018-03-01T02:26:52Z")

</div>

You got `None` if you mistype the node name or the image is invalid.

I would recommend to use `slicer.util.arrayFromSegment()`. It can retrieve voxels directly from segmentation node, you don’t need to export it to labelmap.

---

<div class="post-metadata">

**Author:** ![nodi](https://avatars.discourse-cdn.com/v4/letter/n/57b2e6/32.png) [@nodi](https://discourse.slicer.org/u/nodi)\
**Post date:** [March 1, 2018, 10:08pm UTC](https://discourse.slicer.org/t/tumor-segmentation/2211/7 "2018-03-01T22:08:03Z")

</div>

> [@lassoan](#):
>
> slicer.util.arrayFromSegment()

now I’m getting error.  
Could you please give me the complete steps code maybe I did something wrong.

---

<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:** [March 1, 2018, 11:38pm UTC](https://discourse.slicer.org/t/tumor-segmentation/2211/8 "2018-03-01T23:38:28Z")

</div>

> [@nodi](#):
>
> now I’m getting error.

Sorry, I need more specific information than this to be able to help.

You can get help on usage of any commands by using `help` command. For example: `help(slicer.util.arrayFromSegment)`.

See complete example here: [Area of segment in a given slice? - #3 by lassoan](https://discourse.slicer.org/t/area-of-segment-in-a-given-slice/1559/3)
