Problem creating a mesh

Dear all,

I have a problem creating a mesh.

I have a binary mask containing two (or more) VOIs. I split it up in the different VOIs using the connected component filter and create for each VOI a mesh (see code below). Then I calculate volume and surface iterating over all cells and using an algorithm I wrote. Then I compare volume/surface with the volume and surface I get when I read in each VOI as a separate binary image. But the results are not the same. How can that be? Should the created mesh not always be the same?
Where could be my mistake?
Thanks in advance!


typename ConnectedComponentFilterType::Pointer connectedComponentImageFilter = ConnectedComponentFilterType::New();

//With the label image to shape label map filter the mask is converted to a labeled image
typename LabelImageToShapeLabelMapFilterType::Pointer labelImageToShapeLabelMapFilter = LabelImageToShapeLabelMapFilterType::New();
LabelMapType *labelMap = labelImageToShapeLabelMapFilter->GetOutput();

using LabelMapToLabelImageFilterType = itk::LabelMapToLabelImageFilter<LabelMapType, ImageType>;
LabelMapToLabelImageFilterType::Pointer labelImageConverter = LabelMapToLabelImageFilterType::New();
ImageType::Pointer labeledMask = labelImageConverter->GetOutput();
//For every connected component a labelObject is created
for (unsigned int n = 0; n < labelMap->GetNumberOfLabelObjects(); n++) {
			ShapeLabelObjectType *labelObject = labelMap->GetNthLabelObject(n);
			int labelNr = labelObject->GetLabel();
const PixelType objectValue| = static_cast<PixelType>(1);

meshSource->SetInput(labeledMask );

Do the individual images have the same spacing as the original multi-VOI image? Different spacing would explain it. Also your calculation could be wrong. You could write the meshes to files for both scenarios, and visualize them using Slicer or ParaView to see if there are any differences.

1 Like

Dear Dzenan,

thanks a lot. Your answer helped me to fix the issue. It was indeed my fault. I am storing the points on the mesh in a vector before I calculate the volume. I did not empty this vector after I calculated the volume for one VOI. So it was nothing with ITK :slight_smile: