SCI Seg3D Mailing List

Text archives Help

Re: [Seg3D] Contact CIBC Submission

Chronological Thread 
  • From: Jess <>
  • To: Kelly Nicol <>
  • Cc:, Rob MacLeod <>
  • Subject: Re: [Seg3D] Contact CIBC Submission
  • Date: Thu, 27 Apr 2017 15:49:00 -0600

Hi Kelly,

For the copy and paste, you may have to right click and choose the copy option.  This may be something that we need to look into for the hotkey commands.  You also stumbled on another bug with this new feature.  Some of the commands are copying the wrong syntax for the layerids.  You got the right syntax in the script you sent me, so instead of:
it should be:

Your script is probably failing because it cannot find the ‘wait_for_layer’ function.  you will either need to load the example file I sent, as well as the one you made, or copy the ‘wait_for_layer' function to your file (make sure that you copy the import lines from the top of the file too).  The only other problem that I see is that the output of crop is a list of layer ids, so line 5 should be:

other suggestion for your script is to carry the layer ids from the previous function with the variable names.  ie:
cr_im = crop (…..)
o_ims = otsuthresholdfilter(layerid = cr_ims[0],…)

I’ve attached a version of the script that should work.  You may need to use that last full release to run it, as I just uncovered another bug.  


import os
import threading

def AutoSeg(image_id):
    #  crop parameters orig and size
    # cr_im = crop(layerids=[[layer_0]],origin='[-77.4271,42.3765,-176.008]',size='[193.867,133.897,124.008]',replace='false');
    cr_im = crop(layerids=[image_id],origin='[-77.4271,42.3765,-176.008]',size='[193.867,133.897,124.008]',replace='false');

    #  ostu threshold
    o_ims = otsuthresholdfilter(layerid=cr_im[0],amount='3');

    #  fill holes on third output
    ff_im = fillholesfilter(layerid=o_ims[0],seeds='[[-15.571,105.758,-82.2018]]',replace='false');

    return ff_im

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 27, 2017, at 9:58 AM, Kelly Nicol <> wrote:

Hi Jess, 

Thanks so much for your help. 
As it turns out, the RC version of Seg3D for Mac does not have the same option to copy and paste the commands from the controller window. 
But I got access to a windows program and was able to follow your instructions after that! 
I do have 2 quick follow-up questions. 

(1) I keep getting the error message “exception” 
(2) the wait function “wait_for_layer” kept giving me an error as well. 

Can you think of why this would be the case? Attached is my code and 1
 screen shot of the errors. 


Kelly Nicol

On Apr 21, 2017, 2:43 PM -0400, Jess <>, wrote:
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.  


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

<Screenshot 2017-04-23 22.08.51.png><>

Archive powered by MHonArc 2.6.18.

Top of page