[vtkusers] Background pixel blending in VTK (2D)

David Gobbi david.gobbi at gmail.com
Mon Apr 16 17:42:54 EDT 2018


Hi Kyle,

The vtkImageBlend class requires the images to have identical sampling.
It's possible to get it to overlay an image that is smaller than the base
image, but to do so you need the overlay image to have an "Extent" that
starts at a value greater than zero.  The Extent of an image can be shifted
around with the vtkImageChangeInformation filter.  All in all, it is a huge
hassle, and sometimes it's easier to use vtkImageReslice to resample the
overlay to match the base image.

For all DICOM-viewer apps that I've written recently, I've taken a totally
different approach, and used the VTK image rendering classes that I
contributed a few years ago:
https://www.vtk.org/Wiki/VTK/Image_Rendering_Classes

Some examples are here (they're not great examples, but they exist):
https://gitlab.kitware.com/vtk/vtk/tree/master/Rendering/Image/Testing/Cxx
https://github.com/dgobbi/vtk-dicom/blob/master/Examples/TestDICOMDisplay.cxx

If you don't want to go that far, you might consider using the
vtkImageResliceToColors class to resolve the background issue.
This is a subclass of vtkImageReslice that has a SetLookupTable() method.
It combines reslicing and color mapping into a single operation, so that
when you call SetBackgroundColor() you set the actual RGBA color
directly.

 - David


On Mon, Apr 16, 2018 at 3:19 PM, Kyle Nethery-Pavelchak <
wizardanim2000 at gmail.com> wrote:

> Hi all -
>
> My company is using VTK to render overlaid DICOM images to a screen.
> All of the images in question are single channel intensity mapped
> images encoded in a ushort buffer.
>
> Quick overview of how data is built:
> - vtkImageReslice is hooked into vtkImageMapToWindowLevelColors object.
> - We add a custom lookup table to the window/level colors object.
> - We connect the w/l colors object to a vtkImageMapper.
> - We connect the image mapper to a Actor2D.
> - We then use a vtkImageBlend class and set input connections to two
> channels from the Actor2D generated in the above steps.
>
> For each Actor2D object rendered to the screen, we can control default
> values of pixels on the screen by accessing values within the lookup
> table.  However, for pixels outside the extent of the data being
> drawn, the value appears to always be (0,0,0,1).
>
> We run into issues when considering blending of two images.  We need
> the background image (if larger than the overlay image) to be present
> outside the extents of the overlay image.
>
> I see / have tried various API which seem like they should work - ie:
> vtkImageReslice::SetBackgroundColor, setting default value in lookup
> table, reimplementing the vtkImageBlend class to attempt to access
> these background pixels.
>
> One strange behavior I've noticed, is in the 'SetBackgroundColor(...)'
> function on the reslicer, a value of (x, 0, 0, 0) sets the intensity
> value of the background pixels - i can achieve a white background if i
> set 'x' to be the highest value in our lookup table.  However, the BG
> channels remain 0 and A remains 1 even if i specify 0 in the function.
> I would assume this is because the DICOM image is a single channel
> image, and VTK is generating the background with the same format ..?
>
> I am wondering if anyone has seen/experienced this before, or, knows
> how to work around this kind of issue.
>
> thanks
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180416/4e1b7df0/attachment.html>


More information about the vtkusers mailing list