How to call simpleFilters logic in my python module?

Hello everyone,

I would like to use the SimpleFilter logic in my python module to start a “SigmoidImageFilter” with set parameters.

I looked into : to get some ideas.

I tried this but, it seems i can’t get the module logic and run the “sigmoidImageFilter”

Here is my code :

simplefilterLogic = slicer.modules.simplefilters.logic()
filterParameters["filter"] = "SigmoidImageFilter"
filterParameters["Alpha"] = 2.0
filterParameters["Beta"] = 1.0
filterParameters["OutputMaximum"] = 230.0
filterParameters["OutputMinimum"] = 10.0  filterParameters,  inputVolume, outputVolume)      

Can you help me ?


Try this for getting the logic instead:

import SimpleFilters
simpleFiltersLogic = SimpleFilters.SimpleFiltersLogic()

No i have an error : invalid syntaxe but now the run() function is the good one !

the function need “*inputs” as parameter but i don’t now what is it .,

the last parameter i find it in the source code of the module SimpleFilters

Yes, I see that, unfortunately I don’t have time to dig into this much further and I haven’t used the SimpleFilters module from python before. I did get far enough to see that it looks like that filterParameters.inputs argument is a list of the filter-specific parameters performing the same function as the filterParameters dictionary you constructed above. The relevant code is in these lines (I think), but I haven’t been able to sort out what exactly goes in that list (i.e. whether parameter names are included somehow or whether the values just need to be supplied in an expected order (which I’m sure would match the order in which they appear in the auto-constructed GUI for the SimpleFilters module). I’m sure there are others on this forum who have used SimpleFilters from python who should be able to quickly give you an answer, so hopefully one of them will weigh in soon. Sorry I couldn’t be more help!

1 Like

SimpleFilters provide a GUI to run SimpleITK. If you want to use SimpleITK filters in Python scripting then the easiest is to use SimpleITK directly. See lots of examples here:

There are only two Slicer-specific SimpleITK Python functions - for moving images between SimpleITK and Slicer. See complete examples in 03_Image_Processing_using_SimpleITK notebook and complete specification here:

>>> import sitkUtils

>>> help(sitkUtils.PushVolumeToSlicer)
Help on function PushVolumeToSlicer in module sitkUtils:

PushVolumeToSlicer(sitkimage, targetNode=None, name=None, className='vtkMRMLScalarVolumeNode')
    Given a SimpleITK image, push it back to slicer for viewing
    :param targetNode: Target node that will store the image. If None then a new node will be created.
    :param className: if a new target node is created then this parameter determines node class. For label volumes, set it to vtkMRMLLabelMapVolumeNode.
    :param name: if a new target node is created then this parameter will be used as basis of node name.
      If an existing node is specified as targetNode then this value will not be used.

>>> help(sitkUtils.PullVolumeFromSlicer)
Help on function PullVolumeFromSlicer in module sitkUtils:

    Given a slicer MRML image node or name, return the SimpleITK
    image object.