[vtkusers] Qt, vtkImageView2, image and mask

David Gobbi david.gobbi at gmail.com
Fri Oct 5 09:55:12 EDT 2018


Hi Romain,

The vtkImageViewer2 is only designed for one image, so adding another
vtkImageActor to it will usually not give good results.  Your guess that it
is not showing the same slice is probably correct, but even if it did show
the same slice, the mask might be invisible if it is rendered first instead
of last.

Since your mask is the same size as the image, you can use vtkImageBlend to
combine them into a single image for vtkImageViewer2.  To do this, the
DICOM image would have to go through vtkImageMapToColors to convert it from
grayscale to RGB or RGBA, then the RGBA mask can be added with
vtkImageBlend.

The other option is to create your own vtkRenderWindow instead of using
vtkImageViewer2.  This will give you more flexibility in terms of what you
add to the window and how you interact with it.  For example, see the
following example:
https://github.com/Kitware/VTK/blob/9ac8f74/Examples/ImageProcessing/Python/ImageInteractorReslice.py

Also, in for your mask lookup table you have SetNumberOfTableValues(3) and
SetRange(0,2).  I'm guessing that these were just experimental values,
since a mask should use SetNumberOfTableValues(2) and SetRange(0,1).

Cheers,
 - David

On Thu, Oct 4, 2018 at 11:42 AM Romain LEGUAY <romain.leguay at gmail.com>
wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181005/e2922ad6/attachment.html>


More information about the vtkusers mailing list