# Howto \`totalSegment\` vertebrae\_body with python?

**URL:** <https://discourse.slicer.org/t/howto-totalsegment-vertebrae-body-with-python/35454>\
**Category:** Development\
**Tags:** python, totalsegmentator\
**Created:** [April 12, 2024, 8:50am UTC](https://discourse.slicer.org/t/howto-totalsegment-vertebrae-body-with-python/35454 "2024-04-12T08:50:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [April 12, 2024, 8:50am UTC](https://discourse.slicer.org/t/howto-totalsegment-vertebrae-body-with-python/35454/1 "2024-04-12T08:50:23Z")

</div>

From [SlicerTotalSegmentator](https://github.com/lassoan/SlicerTotalSegmentator/blob/main/TotalSegmentator/TotalSegmentator.py#L488), I extract a function (see 👇🏻) for segment the vertebrae.

```python
_subset = ['vertebrae_S1', 'vertebrae_L5', 'vertebrae_L4', 
           'vertebrae_L3', 'vertebrae_L2', 'vertebrae_L1', 
           'vertebrae_T12', 'vertebrae_T11', 'vertebrae_T10', 
           'vertebrae_T9', 'vertebrae_T8', 'vertebrae_T7', 
           'spinal_cord']
def ttSegVert(inputFile, mNam, taSb=_subset):
# if isinstance(taSb, list):
  outFile = rf'output/{mNam}.nii.gz'
# else:
# outFile = rf'{TMP}/{mNam}'
  import shutil
  ttSegCode = [shutil.which('PythonSlicer'),]
  import sysconfig
  ttSegCode += [os.path.join(sysconfig.get_path('scripts'),
                             "TotalSegmentator")]
  ttSegCode += ['-i', f'{inputFile}', 
                '-o', f'{outFile}', 
                '--fast',
                '--device', 'cpu',]
  if isinstance(taSb, list):
    ttSegCode += ['--ml', '--roi_subset', *taSb]
  else: # [TODO]: 无法完成`taSb='vertebrae_body'`
    ttSegCode += ["--task", taSb]
  print(ttSegCode)
  pros = ut.launchConsoleProcess(ttSegCode).wait()
  print(pros)
  return

```

Well, run `ttSegVert(input, 'ttSegVert', _subset)` , got 👇 a good result.

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

However, run`ttSegVert(inputFile, 'ttSegVert`, ‘vertebrae\_body’)`, got None…

@lassoan @jamesobutler @vertebra

Howto `totalsegment` vertebrae\_body? Or 👆🏻 what’s wrong?

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [April 12, 2024, 9:05am UTC](https://discourse.slicer.org/t/howto-totalsegment-vertebrae-body-with-python/35454/2 "2024-04-12T09:05:09Z")

</div>

Also, I made some modifications to [this code](https://github.com/lassoan/SlicerTotalSegmentator/blob/7aa1ca252261a2b6d026cf58d662286aac904fa3/TotalSegmentator/TotalSegmentator.py#L1169) as 👇:

```auto
            # SampleData.downloadSample('CTLiver')
            logic.process(inputVolume, outputSegmentation, cpu=True, fast = True, task="vertebrae_body")

```

I can get a good result too! 👇

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/e/6e2bb442fb01a3acb3191ad67350a373815e925f.jpeg)
