[vtkusers] Qt, vtkImageView2, image and mask

Romain LEGUAY romain.leguay at gmail.com
Thu Oct 4 13:41:39 EDT 2018


Hello everyone,

I try to add a mask to a 3D image (dicom) with no success.

I followed this example:
https://cmake.org/Wiki/VTK/Examples/Cxx/Images/Transparency

This is the step I follow:

// Load the dicom
vtkSmartPointer<vtkImageData> image = loadDicom(filename);
imageViewer2D->SetInputData(image);
imageViewer2D->GetRenderer()->ResetCamera();
imageViewer2D->Render();

// In a second time

// Load the mask (with the same dimension, origin, spacing as the dicom image
vtkSmartPointer<vtkImageData> maskImage = loadMask(filename_mask);

vtkSmartPointer<vtkLookupTable> lookupTable =
					vtkSmartPointer<vtkLookupTable>::New();
lookupTable->SetNumberOfTableValues(3);
lookupTable->SetRange(0.0,2.0);
lookupTable->SetTableValue( 0, 0.0, 0.0, 0.0, 0.0 ); //label 0 is transparent
lookupTable->SetTableValue( 1, 1.0, 0.0, 0.0, 1.0 ); //label 1 is opaque and red
lookupTable->Build();

vtkSmartPointer<vtkImageMapToColors> mapTransparency = vtkSmartPointer<vtkImageMapToColors>::New();
mapTransparency->SetLookupTable(lookupTable);
mapTransparency->PassAlphaToOutputOn();
mapTransparency->SetInputData(maskImage);
mapTransparency->Update();

vtkSmartPointer<vtkImageActor> maskActor = vtkSmartPointer<vtkImageActor>::New();
maskActor->GetMapper()->SetInputConnection(mapTransparency->GetOutputPort());
maskActor->Update();

imageViewer2D->GetRenderer()->AddActor(maskActor);
imageViewer2D->GetRenderer()->ResetCamera();
imageViewer2D->Render();



When I load my mask and add it using vtkImageViewer2D::SetInputData method, I see correctly my mask.

Is it possible that the image is in first plane and not the mask is hidden by it? If it’s the case, how can I change this behavior?

Thank you,

Romain


More information about the vtkusers mailing list