Smoothing with Gaussian standard deviation changed at some point

I was using the Smoothing segment editor effect recently and noticed a change in results using a typical value for Gaussian standard deviation mm.

A commit from Oct 19th, 2020 ( ENH: Add brush option to Segment Editor Smoothing effect · Slicer/Slicer@52b7208 · GitHub) included changes related to setting the standard deviation of the gaussian filter.

Previous Logic:

standardDeviationMM = self.scriptedEffect.doubleParameter("GaussianStandardDeviationMm")
gaussianFilter = vtk.vtkImageGaussianSmooth()

New logic:

radiusFactor = 4.0
standardDeviationMM = self.scriptedEffect.doubleParameter("GaussianStandardDeviationMm")
spacing = modifierLabelmap.GetSpacing()
standardDeviationPixel = [1.0, 1.0, 1.0]
radiusPixel = [3, 3, 3]
for idx in range(3):
  standardDeviationPixel[idx] = standardDeviationMM / spacing[idx]
  radiusPixel[idx] = int(standardDeviationPixel[idx] * radiusFactor) + 1
gaussianFilter = vtk.vtkImageGaussianSmooth()

Is the changes to setting a pixel value to standard deviation correct rather than a MM value? Had it been previously wrong for so long? Or was there a change in VTK about the input type of SetStandardDeviation?

It appears it was doing gaussianFilter.SetStandardDeviation(standardDeviationMm) since Segment Editor was introduced (ENH: Add new segmentations infrastructure · Slicer/Slicer@3ab0eab · GitHub) back in 2016.

Reviewing the filter documentation for VTK 9 it appears that the standard deviation is indeed in Pixels and that likely the Slicer code had been wrong for a long time. VTK: vtkImageGaussianSmooth Class Reference

Yes, I noticed the issue and fixed it when I implemented and tested the smoothing brush. When the standard deviation happened to be rounded to an even number then the kernel was not symmetric, and a half-voxel shift was visible. Gaussian smoothing is a very blunt tool (removes a lot of information content), therefore the parameter has to be set based on visual appearance anyway, and so the scaling change should not cause major trouble.

Thanks for bringing this up, I’ve added a note to the migration guide to clarify this.

1 Like

Great idea for adding it to the migration guide!