3D segmentation surface with colors

Hi, I’m new to this forum and to VTK. I’m developing a C++ app to automatically segment and analyze the hip. I have a 3D MRI image in ITK format, and the binary segmentation mask already calculated.

I can easily convert the image mask or the masked imaged with itk::ImageToVTKImageFilter. Then create the iso surface with vtkContourFilter and visualize it. But this creates obviously a uniform color when I use a color lookup table for the mapper. I would like to have that the scalar value of the points in surface takes the values from image over (the values at edge of the mask but from image). Does somebody knows how I can achieve this?

I currently trying to manually set the scalars with:

surface->GetOutput()->GetPointData()->SetScalars(XXX)

But for that I first have to fill somehow my vtkFloatArray with the correct values…

I can also use the vtkImageDataGeometryFilter on the masked Image and filter out the 0 values, but this doesn’t give a nice-looking surface.

I also tried to use a stencil, but this didn’t lead to any result so far

I’m pretty sure that someone already had a similar problem than I, but I couldn’t find any answer so far. And there is probably a less hacky solution than manually find and copy the scalars over for the surface. But I’m already happy if it just works.

Thanks Adrian

You can use VTK probe filter for this (if you have trouble using it then you can also use “Probe model with volume” module in 3D Slicer).

However, coloring an isusurface using the same volume that you created the surface from will give you very disappointing results. All surface points will have the same color because you extracted exactly those points that have the same intensity value (you’ll only see a small variation due to sampling and surface smoothing).

Probing the original volume only makes sense for volumetric meshes. You can create high-quality tetrahedral meshes suitable for FEM using Cleaver2. Some people use tetgen, but that tends to crash and has restrictive license.

To get started, the easiest is to do your segmentation in (or import your existing segmentation into) 3D Slicer’s Segment Editor, then create volumetric mesh using SegmentMesher extension (it supports both Cleaver2 an tetgen), then use Probe volume with model to sample the original image. Instead of dense sampling of the original image, you also have the option of splitting your original segmentation two cortical and cancellous bone segments and create a multi-material mesh.

You can also try FeBIO studio, which can start from input surface mesh and assign material properties from a corresponding CT image.

Thanks for your inputs. I think the probe filter is the way to go.

To avoid using the same volume, now I use the original image and the corresponding mask.
With the segmentation mask I create the iso surface. Using it as input for the probe filter and the original image as source.

    vtkSmartPointer<vtkContourFilter> surface =
            vtkSmartPointer<vtkContourFilter>::New();
    surface->SetInputData(vtkCartilageMask->GetOutput());
    surface->ComputeNormalsOn();
    surface->SetValue(0, 1);

    vtkSmartPointer<vtkProbeFilter> probe =
            vtkSmartPointer<vtkProbeFilter>::New();
    probe->SetInputConnection(surface->GetOutputPort());
    probe->SetSourceData(vtkHeadCenterCrop->GetOutput());

But something is wrong, it seems that all the scalars are set to 0.
Do I need to SetFindCellStrategy or something else that it works? Or something else that I missed?

Edit:
It seems to work now.
When I read the images with the vtkNIFTIImageReader then its works as intended. When I convert the images with itk::ImageToVTKImageFilter then the scalars are just 0. But that’s probably another problem.

colored