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

Charlotte Curtis c.f.curtis at gmail.com
Fri Mar 27 13:49:47 EDT 2009


Just a follow-up in case anyone else has this problem: it seems that
vtkActor2D cannot layer with transparency.  Switching to a
vtkImageActor solved the problem, although introducing a few others
(like requiring the data to be unsigned char, meaning some of the
intensity data of the image must be discarded).

Charlotte

On Tue, Mar 24, 2009 at 1:14 PM, Charlotte Curtis <c.f.curtis at gmail.com> wrote:
>
> Hi Jeff, thanks for the reply.
>
> I'm not sure what you mean by exactly the same location - it's true
> that they are at the same xy location, but they are on different
> layers, or at least that's what I'd like them to be doing.  I tried
> changing the Z location with Mapper->SetZSlice, but this just resulted
> in the entire segmentation mask becoming opaque (including the values
> that are mapped through the LUT to an alpha of zero).
>
> I tried setting the opacity of both images to 0.5 as you suggested
> (using actor->GetProperty()->SetOpacity()), and this didn't seem to
> change anything.  Even setting the opacity to zero results in opaque
> images, although if I set the alpha of my LUT values to zero the image
> does indeed disappear.
>
> If I print various values to std::cout, everything seems to be in
> order - for example, overlayRenderer->Transparent() returns 1,
> overlayActor->GetProperty()->GetOpacity() returns whatever I set it to
> (0.5), etc.  I thought perhaps there was something wrong with my
> system graphics/opengl setup, but if I build and run the "medical 3"
> example I do get a transparent volume.  Reading through the code in
> that file, the only difference I could see was that it uses a single
> renderer with multiple actors so I tried that as well, but nothing
> seemed to change.
>
> Thanks again for the help,
>
> Charlotte
>
> On Tue, Mar 24, 2009 at 8:09 AM, Jeff Baumes <jeff.baumes at kitware.com> wrote:
> > 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