Median Image Fiter - command line

Hello all, please, how can I invoke the tool MedianImageFilter through command line?

My Slicer.exe is here: C:\Program Files\Slicer 4.10.2 and MedianImageFilter tools are here: C:\Program Files\Slicer 4.10.2\lib\Slicer-4.10

When I just type “MedianImageFilter” the error message appears that the ITKFactoryRegistration.dll code is not installed. Please, am I doing it right? Please, could you navigate me? I am new to 3D Slicer.

Thanks a lot
Regards
Adam

Hi Adam.

I am certainly not an expert on Slicer programming but if you want to use the median image filter through the python interactor I think this is what you are after…

I have modified this code from the script repository entry here. First go to the data module and remane the volume which you would like to apply the filter to “myvolume”. Then copy and paste the following script into the python interactor.

import SimpleITK as sitk
import sitkUtils

# Get input volume node
inputVolumeNode = slicer.util.getNode('myvolume')

# Create new volume node for output
outputVolumeNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLScalarVolumeNode', 'Median Filtered Volume')

# Run Processing
inputImage = sitkUtils.PullVolumeFromSlicer(inputVolumeNode)
filter = sitk.MedianImageFilter()
# Set inputs for the itk median image filter here
filter.SetRadius(1)
outputImage = filter.Execute(inputImage)
sitkUtils.PushVolumeToSlicer(outputImage, outputVolumeNode)

# Show processed Volume
slicer.util.setSliceViewerLayers(background=outputVolumeNode)

The median filter only takes one input and that is ‘radius’ I have set the radius in the code to 1 as you can see in the line filter.SetRadius(1). You can change the radius input here.

Use this same code structure for using any of the ITK filters. In the python interactor you can type “filter = sitk.” and then press tab to see all the itk filters which are avaliable. It is also useful to find the filter GUI in the “Simple Filters” module to see which input settings the filter has. Then press “filter.Set” and then press tab to find the settings which are available to change for that filter.

Hope this is what you were after.

Yes, running in Slicer with SimpleITK is a good option.

Or if you want to run the module executable directly you need to use the --launch option like this:

C:\Program Files\Slicer 4.10.2\Slicer.exe --launch MedianImageFilter