Segmentation made out of polydata is filled with holes

Hello, my name is Gabriel,

I am in my final year of engineering school and I am relatively new to ITK, VTK, and Slicer. I have a question regarding the functioning of segmentation zones and how they are determined.

I am working on a project for the semi-automatic segmentation of the pulmonary arteries in the lungs. For this, we have a RANSAC algorithm that fits cylinders to the vessels in the lungs and creates a list of points along the vessels’ trajectories. We also retain the radius of the cylinder for each point in the list.

Next, we want to create seeds for the grow-from-seed process. Therefore, we create a new segmentation, and for each point, we create a sphere inside it, slightly smaller than the radius of the corresponding cylinder. These spheres are then added to a vtkAppendPolyData.

Afterward, we add our segment (vtkAppendPolyData.GetOutput()) to our segmentation using AddSegmentFromClosedSurfaceRepresentation.

        for pointIdx in range(len(points)):
            sphere = vtk.vtkSphereSource()
            sphere.SetCenter(points[pointIdx])
            sphere.SetRadius(radius[pointIdx])
            sphere.Update()

            append.AddInputData(sphere.GetOutput())

        append.Update()

        self.segmentationNode.AddSegmentFromClosedSurfaceRepresentation(append.GetOutput(), segment_name, segment_color)

However, the result is disappointing:

It seems that the spheres are intersecting, creating peculiar holes when visualized in Slicer. I have tested visualizing by creating a mesh with Pyvista, and it works fine without these strange holes.

image

Do you know why this is happening and how I could fix it?
I think, it may be because some sphere intersect with each other and the algorithm that interpret weither or not it is a closed surface do It by counting each times it encounter an edge, but I’m unsure.
(Also, if you have any advice on how to better learn ITK, VTK, and Slicer, I would appreciate it.)

It is very hard to see the exact issue, as the screenshot seems not to be enlargeable and this small I cannot see the details that could give away the source of the errors.

This may be a problem, yes. I suggest that instead of appending the polydatas, add the sphere poly datas to a new segment each and then you can use Logical operators to add the sphere segments together. Something like this:

    logicalEffect = segmentEditorWidget.effectByName('Logical operators').self()
    logicalEffect.scriptedEffect.setParameter('Operation', 'UNION')
    for currentSegmentID in sphereSegmendIDs:
      logicalEffect.scriptedEffect.setParameter("ModifierSegmentID", currentSegmentID)
      logicalEffect.onApply()

Then delete the segments you don’t need.

Another issue may be that the segmentation’s binary labelmap image geometry is not ideal. What this means is that when you create a segmentation without a reference volume, it uses a fix RAS-aligned 1x1x1mm^3 geometry, which may be too low resolution. But first let’s see what working around the append filter does.

Another suggestion could. be to add the sphere segments as binary labelmaps instead of polydata. Rasterizing intersecting polydata to a labelmap is a hard problem, but doing it natively as an image is easy. You could script the paint effect with the sphere brush mode turned on or operate directly on the labelmap using something like vtkImageEllipsoidSource.

Hello,

Thank you for your very prompt responses! I tried what @cpinter suggested, and it worked very well!

Here is the result:

As you can see, there are no more holes in the seed area I defined, and by looking between slices I verified it was correct (and it is).

Thank you so much for helping me resolve my issue!

1 Like