Adjusting and saving binary labelmaps

I have cropped ROI volumes that were registered and their segmentations transforms and exported to binary labelmaps. I am trying to save those labelmaps to files that have the same dimensions so that I can create a probabilistic atlas from them. I assumed that the registration and transformation of those segmentations would have constrained the labelmap images to the same dimensions, but I guess I was wrong. Is there a way to shift all of the segmentation labelmaps to have the same number of binary voxels and save those images to be called up in MATLAB to perform the euclidean distance transform and such?

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)

Is there a way to add all of the distance maps generated by the filter and then normalize that output by using the max and minimum distances to get a probabilistic distance atlas in slicer?

Also, can slicer perform efficient belief propagation or markov random fields?

These seem to be basic numpy operations. Typically there is a direct mapping of these simple Matlab functions to numpy - see https://docs.scipy.org/doc/numpy-dev/user/numpy-for-matlab-users.html.

ITK has some MRF filters, you should be able to access them in Python via SimpleITK. There should be tons of other Python-based tools, which you may be able to import into Slicer directly (if they are Python-only). If you need larger, binary packages then for now you need to launch a separate Python interpreter to perform those computations (but this limitation should go away when Slicer is upgraded to use Python3).

Is there a way, that when saving a binary file, you can save the pixel values for a particular object as a specific number that you want? Say you have the object of a target artery among other things in the binary labelmap. Can you save the labelmap with those pixels as 7200, and others as specific codes? Or altering a saved binary labelmap to adhere to those codes?

Probably the easiest is to export the segmentation to a labelmap node and then update voxel values with a numpy: voxelArray[voxelArray > 0] = 7200. See examples in the script repository.