Turn off all smoothing in segmentation

O.S. Win 10 - 64bit
Version: 4.8.1

Hi there,

We are willing to apply this software to segment the thalamus and need to correct segmentation errors on a pixel-by-pixel basis. For this reason, we need to abolish any possible type of smoothing on the source image. Is that by any means possible?

With very best wishes and many thanks in advance,

Leonardo

No smoothing is done on the segmentation (the edited labelmap, which is the master representation) without user intervention. The 3D model is smoothed, but it is only extra visualization. You can turn off model smoothing using the Set surface smoothing option under the arrow next to the Show 3D button in Segment Editor.

Also for the background image you can turn off interpolation to see the original voxel values (interpolation button shown here https://www.slicer.org/wiki/Documentation/4.8/SlicerApplication/MainApplicationGUI#Slice_Viewers)

In general, if it makes significant difference if a single voxel is inside/outside of a segment then it indicates that the data processing workflow is not optimal for segmentation. Most processing and visualization algorithms assume that the image resolution is much finer than size of details in the structures of interest - if you violate this assumption then you’ll get suboptimal results. Increasing image acquisition resolution is often not feasible, but it is not a problem: you can still resample your input volume (preferably to cubic voxel size) before you segment it to avoid problems associated with insufficient image resolution.

You can use Crop volume module to resample with smaller, cubic voxels (Isotropic spacing enabled, Spacing scale set to < 1, Interpolator set to B-spline) and crop to the region of interest (to make sure the output image will not get too big due to the smaller voxel size).

1 Like

Probably you are referring to the interpolation in slice view that is enabled by default.

In the volumes module, in the display tab, there is a check button “Interpolate” which you can deactivate.

Thank you for advice!

About this 3D surface smoothing; I know that when you export your 3D surface smoothed segment as a STL, the viewport smoothing is also applied on the final exported STL.
But what method is used for this smoothing? Which algorithm and settings do I have to use to perform the same smoothing on for instance a labelmap?
In other words; can exactly the same procedure be done afterwards and how?

Or is that a well kept secret? :wink:

I’m asking this because I’m trying to mimic a smoothing method that’s used by the applications ‘Mimics’ and ‘3D-Matic’ (both products of Materialise). It’s proprietary software, so they won’t let you how they do their thing. :zipper_mouth_face:

Smoothing is not actually applied when exporting. Whatever you have as closed surface representation, that is what is exported. If you disable smoothing when editing, then it won’t be smoothed.

Nothing is a secret in Slicer :slight_smile: Flying edges is used for smoothing. See usage here


and the method here
https://vtk.org/doc/nightly/html/classvtkDiscreteFlyingEdges3D.html (scroll down for the description)

Most of the smoothing is provided vtkWindowedSincPolyDataFilter applied on the flying edges output:

May I change the smoothing method for the closed surface?

Yes! This is an underutilized feature in the segmentation infrastructure: you can specify any number of alternative conversion rule(s) that can get from a binary labelmap to a closed surface representation. The conversion path with the smallest cost is used by default, but to can choose alternative path when you click on Update in the representation list in Segmentations module.

What algorithm do you have in mind?

Is it the method you said? It seems some parameters can be changed, but the method can’t be changed to another smoothing one. Actually, I just want to see the segmentation result without any postprocessing like the example from VTK.

You can turn off smoothing very easily in Segment Editor, see Show 3D option in the documentation.

For existing segmentations you just change the smoothing factor to 0 (see second parameter in the red box in your screenshot).

Hello! Do you know if there is a way to change the default setting so that it always sets the smoothing factor to 0?

Smoothing step is part of the reconstruction. It is not some optional postprocessing step that you may or may not want to have. If you don’t apply smoothing then you will get a surface corrupted with aliasing artifacts (staircases), which are not there in the continuous signal. Therefore, you should not disable smoothing by default.

Of course, you can do everything in Slicer. So, if you decide that you always want to have artifacts in the reconstructed surface then you can change the default by adding these lines to your .slicerrc.py file:

# Note: running this code is not recommended, as it introduces artifacts in the reconstructed surface
defaultSegmentationNode = slicer.vtkMRMLSegmentationNode()
defaultSegmentationNode.GetSegmentation().SetConversionParameter("Smoothing factor", "-0.5")  # use negative number to make it easy to enable smoothing
slicer.mrmlScene.AddDefaultNode(defaultSegmentationNode)

This is wise and useful information that should be prominently placed somewhere.

This is still a confusing topic. Please consider the 2 images below.

In the first one, there is no surface smoothing in 3D. In the second image, surface smoothing is at default 0.5.

We see that the contrasted structure is better filled without surface smoothing in the the 3D view. The slice view outlines the contrast as reference.

Should we consider that surface smoothing should be applied in 2D views to remove what is considered as artifacts? But the contrast pleads against this.

Yes it is indeed due to scenarios like this one that I did not want to have any smoothing. I tried the code suggested:

defaultSegmentationNode = slicer.vtkMRMLSegmentationNode()
defaultSegmentationNode.GetSegmentation().SetConversionParameter("Smoothing factor", "-0.5")  # use negative number to make it easy to enable smoothing
slicer.mrmlScene.AddDefaultNode(defaultSegmentationNode)

However, it did not work as I hoped. I want to make it so that whenever I load a segmentation and click “Show 3D” the visualisation has a smoothing factor of 0. However, after adding this code to .slicerrc.py, the default smoothing factor is still 0.5. I really want to change this default setting as in my workflow I have to load many segmentation files, and each time I have the change the smoothing factor manually.

Did you restart Slicer after updating .slicerrc.py?

Yes I did. I also tried running those codes in the python console inside slicer to ensure that they were applied, but neither worked.