[vtkusers] Transparency of binary segmentation mask (ImageActor2D + LUT)

Charlotte Curtis c.f.curtis at gmail.com
Mon Mar 23 21:38:01 EDT 2009

Hi all,

I've got a couple of images displayed on top of each other, one a 2D
medical image, and the other a binary segmentation mask.  They each
have their own image actors and renderers, and I created a lookup
table for the segmentation mask in the hopes that it would let me
render the mask as semi-transparent colours.  Right now I've got two
values in the LUT (corresponding to the image values of 0 and 1), and
I can change the colours, but the transparency is binary - if I set
the alpha value to 0, it doesn't display, but if it's anything else
(even 0.001) then the mask is completely opaque.

I've also tried changing the opacity of the actor
(actor->GetProperty->SetOpacity()), but this doesn't seem to do
anything, although when I print out the value of the actor's opacity
it thinks that it is set correctly.

Perhaps my window/levels are wrong?  I'm kind of at a loss.  Apologies
if this has been asked (seems like a common problem, but I couldn't
find a solution so far).  Thanks,


// Create the common components for the image viewer
vtkRenderWindow* renWin = vtkRenderWindow::New();
vtkRenderWindowInteractor* interactor = renWin->MakeRenderWindowInteractor();
interactor->SetRenderWindow( renWin );

// Create the components for the image display
vtkRenderer* imageRenderer = vtkRenderer::New();
vtkActor2D* imageActor = vtkActor2D::New();
vtkImageMapper* imageMapper = vtkImageMapper::New();

// Set the values and connect them together
imageMapper->SetColorWindow( 1024 );
imageMapper->SetColorLevel( 512 );
imageMapper->SetInput( connector->GetOutput() );
imageActor->SetMapper( imageMapper );
imageRenderer->AddActor( imageActor );

// Create the components for the mask layer
vtkRenderer* overlayRenderer = vtkRenderer::New();
vtkActor2D* overlayActor = vtkActor2D::New();
vtkImageMapper* overlayMapper = vtkImageMapper::New();
vtkLookupTable* overlayLUT = vtkLookupTable::New();
vtkImageMapToColors* colourMapper = vtkImageMapToColors::New();

/************************* This is the part that's not behaving
// set properties of the various overlay components
//overlayActor->GetProperty()->SetOpacity( 0.5 ); this doesn't seem to
do anything
double outsideColour[4] = {1.0, 0, 0, 0.5};  // This one shows up as
completely opaque red.
double insideColour[4] = {1.0, 1.0, 1.0, 0}; // This one doesn't show,
which is correct.
overlayLUT->SetTableRange(0, 1);
overlayLUT->SetTableValue( 0, outsideColour );
overlayLUT->SetTableValue( 1, insideColour );
overlayMapper->SetColorLevel( 0.5 );
overlayMapper->SetColorWindow( 0.5 );

// Connect the overlay stuff together
colourMapper->SetLookupTable( overlayLUT );
colourMapper->SetInput( binConnector->GetOutput() );
overlayMapper->SetInput( colourMapper->GetOutput() );
overlayActor->SetMapper( overlayMapper );
overlayRenderer->AddActor( overlayActor );

// Connect everything together
renWin->SetSize( size[0], size[1] );
renWin->SetNumberOfLayers( 2 );
renWin->AddRenderer( imageRenderer );
renWin->AddRenderer( overlayRenderer );
imageRenderer->SetLayer( 0 );
overlayRenderer->SetLayer( 1 );

// Look at the pretty picture!

More information about the vtkusers mailing list