# Segment Skeletal thorax (Ribs, Thoracic spine and sternum)

**URL:** <https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600>\
**Category:** Support\
**Created:** [March 17, 2021, 6:20pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600 "2021-03-17T18:20:59Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![colabwarrior](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/colabwarrior/32/10331_2.png) [@colabwarrior](https://discourse.slicer.org/u/colabwarrior)\
**Post date:** [March 17, 2021, 6:20pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/1 "2021-03-17T18:20:59Z")

</div>

Hi,

I am trying to use slicer to isolate the skeletal thorax from DICOMS. I am working with threshold, islands and scissors tool but I am not able to isolate the bones cleanly. Soft tissue, organs, scan bed shows up in the segmented image. Plus same threshold range captures different stuff for different DICOMS. I have two questions:

1. Is there a way to cleanly segment the bones?
2. I have over 600 DICOMS from which I need to isolate the skeletal thorax (bones). How can I do this using Python script?

Thanks,  
Vik

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [March 18, 2021, 5:18pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/2 "2021-03-18T17:18:14Z")

</div>

Hi Vik,

My personal preference for segmentation of thoracic skeletal bones is using the new “local threshold” function of the “Segment Editor”, but this requires a few mouseclicks for each dataset. Another option would be the involvement of “Grow from Seeds” as described in this thread: [Bone segmentation to create 3D-printable STL](https://discourse.slicer.org/t/bone-segmentation-to-create-3d-printable-stl/960)

Once you have defined a good workflow you can try to integrate it into a python script that loads the DICOM dataset, then lets you do the manually assisted segmentation, automatically saves the results, and switches to the next patient.

Regards,  
Rudolf

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [March 19, 2021, 8:19am UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/3 "2021-03-19T08:19:44Z")

</div>

PS for detailed and almost instant overviews of the thoracic bone structures you can use “Volume Rendering” and the “CT-AAA” preset.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/d/8dfd13a782229cf6af16be25708797a798b5ad70.jpeg)

---

<div class="post-metadata">

**Author:** ![colabwarrior](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/colabwarrior/32/10331_2.png) [@colabwarrior](https://discourse.slicer.org/u/colabwarrior)\
**Post date:** [March 19, 2021, 2:24pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/4 "2021-03-19T14:24:48Z")

</div>

Thanks Rudolf. I have the latest version 4.11 but I do not see any “local threshold” function. Is it in v5.0 and is there any tutorial on it?

---

<div class="post-metadata">

**Author:** ![colabwarrior](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/colabwarrior/32/10331_2.png) [@colabwarrior](https://discourse.slicer.org/u/colabwarrior)\
**Post date:** [March 19, 2021, 2:33pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/5 "2021-03-19T14:33:32Z")

</div>

Thanks Rudolf. If I use the “CT-AAA” preset, can I save the displayed parts directly. Also in “CT-AAA” preset, scan bed shows up with some other noise. So it is still not a clean bone segmentation. [Annotation 2021-03-19 102944|400x347](https://discourse.slicer.org/uploads/short-url/4tX1DVWQA9xOPn2t48diw6UVN8N.jpeg) . Any suggestion is highly appreciated. Thanks again.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [March 19, 2021, 2:38pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/6 "2021-03-19T14:38:10Z")

</div>

You will find it after installing the “Segment Editor Extra Effects” extension from the extensions manager.

More information on the effect see here: [New Segment Editor effect: Local threshold - #7 by sfglio](https://discourse.slicer.org/t/new-segment-editor-effect-local-threshold/9233/7)

It is important to remember that - after selection of a “bone” threshold - you need to left click into one of the slices (onto the bone) to add to the new segmentation.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [March 19, 2021, 2:43pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/7 "2021-03-19T14:43:05Z")

</div>

CT-AAA: Adjust the “shift” slider a bit right or left to remove or include unwanted areas

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/0/70ab2c2d9c55ef4e03f48af376b3cf369cb7393e.png)

Please remember, that you are working with volume rendering here, you will not get any kind of 3D printable segment or segment statistics, it is is just a quick visual 3D representation of the volume.

---

<div class="post-metadata">

**Author:** ![colabwarrior](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/colabwarrior/32/10331_2.png) [@colabwarrior](https://discourse.slicer.org/u/colabwarrior)\
**Post date:** [March 19, 2021, 2:44pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/8 "2021-03-19T14:44:01Z")

</div>

Thanks Rudolf. I was looking at the “CT-AAA” preset and if I move the shift parameter it does help a lot but these lines from the scan bed show up. Not sure how to eliminate those. Also can I save only the displayed parts from this “CT-AAA” preset to a new file (DICOM, NIFTI etc.)

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [March 19, 2021, 2:56pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/9 "2021-03-19T14:56:30Z")

</div>

Sure, enable Crop and check ROI as shown here:

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/a/cab45f8fbd7f4f11e4e6ae4d2bee4ac3fcc88c9b.png)

then you can crop away the table artefact by moving the ROI box markers around

---

<div class="post-metadata">

**Author:** ![colabwarrior](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/colabwarrior/32/10331_2.png) [@colabwarrior](https://discourse.slicer.org/u/colabwarrior)\
**Post date:** [March 19, 2021, 3:04pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/10 "2021-03-19T15:04:30Z")

</div>

Thanks. Is there a way to save this rendered volume only?

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [March 19, 2021, 3:43pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/11 "2021-03-19T15:43:43Z")

</div>

As no “real” 3D segmentation is generated in volume rendering, you would just save (“File” → “Save”) the scene into a directory of your choice.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/1/410630d43e953f9df485ffaf56d0e13c894bf869.png)

Calling the “\*.mrml” file later will reopen your volume rendering exactly as you have left it.

Also have a look at saving from 3D Slicer into a “\*.mrb” bundle - this will save the complete data set into one single file.

---

<div class="post-metadata">

**Author:** ![colabwarrior](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/colabwarrior/32/10331_2.png) [@colabwarrior](https://discourse.slicer.org/u/colabwarrior)\
**Post date:** [March 23, 2021, 4:28pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/12 "2021-03-23T16:28:50Z")

</div>

Hello Rudolf,

I saved the file as a \*.mrb file. Is there a way to extract the 3D array of the CT-AAA preset. I want to use the array for machine learning. Thanks

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [March 23, 2021, 5:11pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/13 "2021-03-23T17:11:39Z")

</div>

That sounds very interesting.

A quick google search revealed this thread:

> [@How to set volume rendering preset using Python](https://discourse.slicer.org/t/how-to-set-volume-rendering-preset-using-python/3063/2):
>
> Hi Oliver, There have been some improvements since 4.8.1 that makes it easier for us to do this. So if you use the latest nightly, then this is what you can do: Easier setup of volume rendering (no need to create the display node and update it from the logic): volRenLogic = slicer.modules.volumerendering.logic() displayNode = volRenLogic.CreateDefaultVolumeRenderingNodes(volumeNode) This is not very clean, because it uses widgets from the volume rendering module, but you can apply a shift li…

which may get you started …  
What is the goal of your trial in the end, what do you need to see?

Best regards  
Rudolf

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [March 23, 2021, 5:16pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/14 "2021-03-23T17:16:24Z")

</div>

The CT-AAA preset is pretty close to a straight threshold. You can see the transfer function in the Volume Rendering module, under Advanced…

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/6/76e2d63386fdc8ed7e38074fdc9d189d75113bdb.png)

The effective threshold is where Point 2 is in the transfer function. Note that this slides back and forth with the “Shift” slider, so you want to identify the value of Point 2 when you like how the volume rendering looks.

If you want a volume output, you can generate a thresholded volume easily in a couple different ways (see [Documentation/Nightly/ScriptRepository - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Modify_voxels_in_a_volume) for an example). However, if this is good enough training data for your ML project, then essentially all you are doing is teaching it to apply a binary threshold, which you hardly need machine learning for…

If you need to do something more complex, then you basically need to figure out a workflow that works well on some of your example images, and if you are lucky and it requires no manual decisions on a per-image basis, then you can fully automate it and try it on the rest of your 600 images. If it still requires user judgement on every image, you can still create a facilitated workflow which will speed your processing of the remaining images, but that’s the best you can do.

---

<div class="post-metadata">

**Author:** ![colabwarrior](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/colabwarrior/32/10331_2.png) [@colabwarrior](https://discourse.slicer.org/u/colabwarrior)\
**Post date:** [March 23, 2021, 5:20pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/15 "2021-03-23T17:20:33Z")

</div>

I am developing computational Human models and need to come up with an average thorax geometry for males and females for injury analysis.

Also in the link you sent, it does not say how to store the CT-AAA preset as a 3D array, which can be opened with Numpy and not Slicer. Is that possible? Thanks

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [March 23, 2021, 5:38pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/16 "2021-03-23T17:38:21Z")

</div>

```
import numpy as np
imageVolumeNode = getNode('ThoraxImage') # replace with the name of your volume
thresholdValue = 350 # whatever threshold value you want
imageNumpyArray = slicer.util.arrayFromVolume(imageVolumeNode)
threshIm = imageNumpyArray > thresholdValue
with open('numpyOutput.npy', 'wb') as file_handle:
  np.save(file_handle, threshIm)

```

This will threshold your entire volume at 350 HU, and save the output logical numpy array to “numpyOutput.npy” (which can be loaded into numpy using numpy.load()). Note that this will not crop out the table, as you might have in the volume rendering. To do that, you can use the CropVolume module using the same ROI as you used in the volume rendering module. Then, in the code snippet above, use the name of the cropped volume node rather than the original volume (or you can just have the cropped volume replace the original volume by selecting it as the output volume in “CropVolume” instead of “Create new volume”.

---

<div class="post-metadata">

**Author:** ![colabwarrior](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/colabwarrior/32/10331_2.png) [@colabwarrior](https://discourse.slicer.org/u/colabwarrior)\
**Post date:** [March 23, 2021, 5:41pm UTC](https://discourse.slicer.org/t/segment-skeletal-thorax-ribs-thoracic-spine-and-sternum/16600/17 "2021-03-23T17:41:12Z")

</div>

Thanks Mike. This is really helpful.
