Question on Fill Between Slices algorithm

Hello again,

I have a question regarding the “fill between slices” operation. When I perform this operation, I don’t see a smooth surface in the 3D view when clicking “show 3D.” It appears that the preview model has a lot of irregularities in the surface. Please find the attached screen capture and video that demonstrate how I generated the preview.

Video Reference: FillBetweenSlices.mp4 - Google Drive
Screen Capture:

Additionally, in the preview, the top and bottom slices are not as smooth as when using a round paintbrush. It’s noticeable that there are many triangles in the top and bottom slices surface, and the fill between slices appears to have a somewhat rectangular surface.

So, my question is: why doesn’t it have a smooth slope?

@lassoan @pieper Any thoughts?

Try resampling the data to isotropic resolution using the CropVolume before you start the segmentation. In the video you skipped that step (MRHead has anisotropic voxel spacing, 1x1x1.3mm). That should help.

You can also increase the resolution of the segmentation using the Segment Geometry option, and oversample.

1 Like

Hello @muratmaga,

Thank you for the suggestion. I’ve implemented your proposed solution and noticed a significant reduction in the number of triangles and the steps on the surface.

I have one more question. As you can see in the following images, the FIRST and LAST slices are circular then I’ve applied the multiple slice edit in the output, intermediate interpolated slices appear to have a square shape.

Image-1:

Image-2:

Image-3:

Eventually it should be tapered cone like interpolation as shown in the below GIF:
SlicerCapture

How to address this issue?

Not sure. try turning of the smoothing for the model creation (under the show 3D options).

I tried disabling the smoothing option, but it didn’t work.:

The diamond-shaped cross-section is just a result of how distance is estimated by a series of morphological operations (one voxel dilation in diagonal direction is 1.44x longer than in sideways, therefore repeated dilations result in a diamond shape). You can find more detailed description of the algorithm at https://insight-journal.org/browse/publication/977

You can switch to a distance transform based dilation instead of repeated morphological dilations, which will provide more rounded cross-sections. For this, you just need to add a single line to SegmentEditorFillBetweenSlicesEffect.py:

Before SetInputData(...) line, add this line:

interpolator.SetUseDistanceTransform(True)

However, in general these small details should not matter: wherever you don’t find the interpolated contour to be accurate enough, you can segment an additional slice there (and the 3D interpolation result will be updated automatically).

If you want to reconstruct a surface from extremely sparse contours using linear interpolation then you can use SlicerRT module’s planar contour to closed surface converter rule. This is used when importing DICOM RT structure sets, or when converting OsiriX ROIs to segmentations.

If you want to reconstruct a tubular surface then the easiest may be to use vtkTubeFilter.

What is your use case? Why do you attempt to reconstruct a 3D surface from cross-sections that are so extremely far from each other?

1 Like

@lassoan Thanks for your suggestions.

I tried distance transform-based dilation, but I don’t see much difference in the voxel dilations as shown in the above images. Yes, if we look from the top view of the model, we see somewhat rounded cross-sections better than compared to the previous approach.

Yes, I want to reconstruct tubular surfaces but with varying radii. For example, consider the sideway figures below. Imagine the white lines as the diameter of a round brush. What I want is to reconstruct a tubular-like surface between these slices.

For the resulting model to be accurate when using a round paint brush, the filled area between the slices, specifically the surface, should have a rounded cross-section.

Probably adding interpolator.SetUseBallStructuringElement(True) will provide the result you expect. We may make it the default, as it indeed a more natural-looking interpolation when segmented slices are very far from each other.

Unfortunately, the result still looks the same to me after setting this to True.

Here’s the output:

I was expecting the surface to be like this (marked in orange):

I compared all the combinations of the two flags and it seems that actually UseDistanceTransform gives the best result.

UseDistanceTransform = False, UseBallStructuringElement = False:

UseDistanceTransform = False, UseBallStructuringElement = True:

UseDistanceTransform = True (UseBallStructuringElement value does not make any difference):

1 Like

I tried the flag UseDistanceTransform in 5.6.2, and hopefully, it is giving me expected results.

However, if we look into the sagittal view, you will notice the surface looks like something Concave. Also, in the top view of 3D, it seems like the filled area is squeezed from anterior and posterior (which I believe results in the Concave-like surface).

I wonder if there is any underlying parameter affecting the surface, or if the algorithm itself produces this type of surface?

This output looks very good. The smoothness is intentional (you don’t want linear interpolation, as it would result in discontinuity in surface normal directions).

The cross-section is slightly oval because of the distance map is computed without taking spacing into account. Normally this is not visible because segmented slices are at a reasonable distance, while in your case it is extreme (it is almost impossible that an interpolation algorithm would correctly guess a 3D shape from such extremely sparse data) and you interpolate on axial slices and the spacing is uniform within a slice (but MRHead is an unusual image where the image spacing is slightly larger along the LR axis).

I would recommend to add contours more closer to each other and consider resampling your image to isotropic spacing (which is useful for 3D segmentation anyway).

While in practice ignoring the image spacing for the distance transform should not be a problem, you can still request a fix here and see what the developers say.