Adjusting and saving binary labelmaps

When you export to Segmentation to Labelmap in Segmentations module’s Export-import section, in the Advanced section you can set a Reference volume. Segments will be padded/resampled to have the same geometry as the Reference volume.

Note that with numpy, SimpleITK, VTK, etc. libraries readily available in Slicer in Python, it’s hard to find anything that is worth sent to be computed in Matlab.

For example, you have several distance map computation algorithms in SimpleITK that you can call directly from Slicer. Just load MRHead sample volume and copy-paste this into the Python console:

import SimpleITK as sitk
import sitkUtils

intputVolumeNode = getNode('MRHead')
inputImage = sitkUtils.PullVolumeFromSlicer(inputVolumeNode)

dtFilter = sitk.SignedMaurerDistanceMapImageFilter()
dtFilter.SetSquaredDistance(False)
outputImage = dtFilter.Execute(inputImage)
    
outputVolumeNode = sitkUtils.PushVolumeToSlicer(outputImage, name='DistanceMap')
slicer.util.setSliceViewerLayers(background = outputVolumeNode)