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

Jeff Baumes jeff.baumes at kitware.com
Tue Mar 24 10:09:13 EDT 2009


It looks like the images are displayed at exactly the same location? I
believe the image mapper maps a texture to a quad, so perhaps you have
conflicting geometry. The other thing I would try is to set the
opacity of both images to less than 1.0 (like 0.9 and 0.5), so that
they are both rendered in the same render pass. VTK first renders any
opaque geometry, then renders translucent geometry, so that may be why
it gets obscured.

Jeff

On Mon, Mar 23, 2009 at 9:38 PM, Charlotte Curtis <c.f.curtis at gmail.com> wrote:
> 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,
>
> Charlotte
>
> // 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->SetNumberOfTableValues(2);
> overlayLUT->SetTableRange(0, 1);
> overlayLUT->SetTableValue( 0, outsideColour );
> overlayLUT->SetTableValue( 1, insideColour );
> overlayLUT->Build();
> 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!
> renWin->Render();
> interactor->Start();
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



-- 
Jeff Baumes, Ph.D.
R&D Engineer, Kitware Inc.
(518) 371-3971 x132
jeff.baumes at kitware.com



More information about the vtkusers mailing list