SCI Seg3D Mailing List

Text archives Help

Re: [Seg3D] Contact CIBC Submission

Chronological Thread 
  • From: Jess <>
  • To:,
  • Cc: Rob MacLeod <>
  • Subject: Re: [Seg3D] Contact CIBC Submission
  • Date: Fri, 21 Apr 2017 12:43:30 -0600

Hi Kelly,

Writing scripts for Seg3D there are a couple things that should help. 

 First, in the newest release candidate ( there is a new feature which you can copy the python functions from the controller window.  This means that you can load an example data, perform the steps that you want, then copy the functions from the controller window and into a script file.  If you are using an older version, you can still use the controller window to get the functions and parameters that you use, but you will need to convert it to python syntax, which isn’t too similar.  

The second aspect that you need to consider is that the python scheduler doesn’t necessarily wait for the the tools to finish before attempting the next on.  Therefore, you need a wait function to allow the filters to run in series.  There is an example attached that has the wait function.

Because of the need for a wait function, I usually make scripts in the form of a function or a library.  In the attached example, there is a function that loads the data (dicom format in this case), and some other things.  It also calls the second function, which performs a series of filters and tools similar to what you want to do. You can run this example with the following functions in the python console window (it uses data from the IBBM example data, and there is a similar data set in the SCIRun dataset):

path = ‘[path to IBBM dir]/2016/Image_Processing/Lab2/'
exec(open('[path to IBBM dir]/2016/Python_Labs/Lab1_Seg3D/scripts/').read())
AutoSeg_file(path+'DICOM/',path,'seg_auto', [29877, 2121],[[-2.81,5.61,35.8]])

You can use this example, and modify the second function to fit your needs.  It will be something like this:

def AutoSeg(layer,orig,sz,seed):
  #crop with parameters orig and sz
  #filter with median filter radius 1
  sm_im = medianfilter(layerid = cr_im,radius=1)
  #otsu threshold gives multiple outputs

  # fill holes on third otsu output

  return ff_im

the parameters from the parent function should look like:
orig = '[-78.3714,-74.658,6.01]'
seed = [[-2.81,5.61,35.8]]

These examples should hopefully get you started.  There are some more python script examples in the IBBM data, and at 

Please let me know if you have more questions.  


import os
import threading

def AutoSeg_file(Filepath, outputfilename,name, thresh,seed):
# runs topical denoising on an image
  if not os.path.exists(Filepath):
    raise ValueError("Path %s does not exist." % Filename)
  files = os.listdir(Filepath)


  for f in files:

#load data
  im_layer = importseries(filenames=Filenames, importer='[Teem Importer]', mode='data')


  # set name
  #save seg
  result=exportsegmentation(layers=sm_seg,file_path=outputfilename ,exporter='[NRRD Exporter]',extension='.nrrd')

def AutoSeg(layer,thresh,seed):

#smooth image
  sm_im = medianfilter(layerid = layer,radius=1)
#threshold image
  thresh_im=threshold(layerid = sm_im, lower_threshold = thresh[0], upper_threshold = thresh[1])
  #connected componten
  cc_im = connectedcomponentfilter(layerid = thresh_im, seeds = seed)
# smooth segmenation
  sm_seg_1 = dilateerodefilter(layerid=cc_im,dilate_radius=0, erode_radius = 1)
  sm_seg = dilateerodefilter(layerid=sm_seg_1,dilate_radius=2, erode_radius = 1)

  return sm_seg

def wait_for_layer(layer):

#checks to make sure that the layer is available before trying operations on it.

  c = threading.Condition()
  layerStatus = get(stateid=layer+"::data")
  counter = 1
  with c:
    while not layerStatus == "available":
      if counter > MAX_ITERATIONS:
      counter += 1
      layerStatus = get(stateid=layer+"::data")
      print('waiting for '+layer)

On Apr 20, 2017, at 3:43 PM, SCI Webmaster <> wrote:

Kelly Nicol <>

Affiliation: Mount Sinai - Dept Neurosurgery

Re Software: {Software:value}

Subject: Python Console

Message: Hi there!
I attended IBBM last year. You showed us how to semi-automate our segmentations in Seg3D with this tool. I can only code for the command line and was wondering if you could help me code 4 steps for some cardiac CT scans I'm working on. (1) cropping (2) median filtering radius =1 (3) 3 part otsu threshold (4) fill holes filter
Shouldnt be too bad, but could really use your help! Thanks...Kelly

Archive powered by MHonArc 2.6.18.

Top of page