[vtkusers] differences in window/leveling (new, no so big, attachment)

David Gobbi david.gobbi at gmail.com
Mon Dec 17 17:24:53 EST 2012


Your image is dark because you are applying the window/level
_after_ you have converted the image to RGB.  After the image
is RGB, it has values in the range [0,255].  So of course if you
apply a window/level of 1995/998 to such an image, the result
is going to be very dark.

To summarize: you can apply the window/level with
vtkImageMapToColors, or you can apply the window/level
with vtkImageProperty, but _not with both_.

Two ways to fix:


Option #1: Apply window/level with vtkImageMapToColors

lut.SetRange(level-0.5*window, level+0.5*window)
image_property.SetColorWindow(255.0)
image_property.SetColorLevel(127.5)


Option #2: Apply window/level with vtkImageProperty:

Remove vtkImageMapToColors from your pipeline (completely!)
image_property.SetColorWindow(window)
image_property.SetColorLevel(level)
image_property.SetLookupTable(lut) # optional

 - David


On Mon, Dec 17, 2012 at 2:48 PM, José M. Rodriguez Bacallao
<jmrbcu at gmail.com> wrote:
> sorry, the attachment was a little big so I had to scale it down, here is
> again:
>
> hello, while I was testing a dicom viewer I am developing I noticed
> differences in window leveling from the pipeline I am using with respect to
> one of the viewers I use as reference. I attached the snapshot, the left
> window is my viewer and the right is one of my reference viewers. Both have
> the same window/level: 1995/998, but the image displayed at left is darker
> than right, here is part of the pipeline I use:
>
>         vtk_image = image.vtk_image
>         self.view = vtk.QVTKWidget(self)
>         self.view.setFocusProxy(self)
>         # add the view to the internal layout
>         self.setUpdatesEnabled(False)
>         self.layout().takeAt(1)
>         self.layout().addWidget(self.view)
>         self.setUpdatesEnabled(True)
>
>         # create the main interactor style
>         style = vtk.vtkInteractorStyleImage()
>         style.SetInteractionModeToImageSlicing()
>
> self.view.GetRenderWindow().GetInteractor().SetInteractorStyle(style)
>
>         # the axial orientation
>         style.SetZViewRightVector((1, 0, 0))
>         style.SetZViewUpVector((0, -1, 0))
>
>         # the sagital orientation
>         style.SetXViewRightVector((0, 1, 0))
>         style.SetXViewUpVector((0, 0, 1))
>
>         # the coronal orientation
>         style.SetYViewRightVector((1, 0, 0))
>         style.SetYViewUpVector((0, 0, 1))
>
>         image_mapper = vtk.vtkImageResliceMapper()
>         image_mapper.SliceFacesCameraOn()
>         image_mapper.SliceAtFocalPointOn()
>         image_mapper.JumpToNearestSliceOn()
>         image_mapper.BorderOff()
>         self.image_mapper = image_mapper
>
>         format = image.image_format
>         if format in (vtkgdcm.VTK_LOOKUP_TABLE,
> vtkgdcm.VTK_INVERSE_LUMINANCE):
>             lut = vtk_image.GetPointData().GetScalars().GetLookupTable()
>
>             if isinstance(lut, vtkgdcm.vtkLookupTable16):
>                 color_filter = vtkgdcm.vtkImageMapToColors16()
>             else:
>                 color_filter = vtk.vtkImageMapToColors()
>
>             color_filter.SetInputConnection(vtk_image.GetProducerPort())
>             color_filter.SetLookupTable(lut)
>
>             if format == vtkgdcm.VTK_LOOKUP_TABLE:
>                 color_filter.SetOutputFormatToRGB()
>             elif format == vtkgdcm.VTK_INVERSE_LUMINANCE:
>                 color_filter.SetOutputFormatToLuminance()
>
>             color_filter.Update()
>             scalar_range = color_filter.GetOutput().GetScalarRange()
>             image_mapper.SetInputConnection(color_filter.GetOutputPort())
>             del color_filter
>         elif format == vtkgdcm.VTK_YBR:
>             color_filter = vtkgdcm.vtkImageYBRToRGB()
>             color_filter.SetInputConnection(vtk_image.GetProducerPort())
>             color_filter.Update()
>             scalar_range = color_filter.GetOutput().GetScalarRange()
>             image_mapper.SetInputConnection(color_filter.GetOutputPort())
>             del color_filter
>         else:
>             scalar_range = vtk_image.GetScalarRange()
>             image_mapper.SetInput(vtk_image)
>
>         try:
>             # here the window width will be: 1995 and window level: 998
>             level = image.window_level[0]
>             window = image.window_width[0]
>         except KeyError, IndexError:
>             window = scalar_range[1] - scalar_range[0]
>             level = 0.5 * (scalar_range[1] + scalar_range[0])
>
>         image_property = vtk.vtkImageProperty()
>         image_property.SetColorWindow(window)
>         image_property.SetColorLevel(level)
>         image_property.SetAmbient(0.0)
>         image_property.SetDiffuse(1.0)
>         image_property.SetOpacity(1.0)
>         image_property.SetInterpolationTypeToLinear()
>         self.image_property = image_property
>
>         image_actor = vtk.vtkImageSlice()
>         image_actor.SetMapper(image_mapper)
>         image_actor.SetProperty(image_property)
>         self.image_actor = image_actor
>
>         image_renderer = vtk.vtkRenderer()
>         image_renderer.SetBackground(0, 0, 0)
>         self.image_renderer = image_renderer
>         image_renderer.AddViewProp(image_actor)
>         image_renderer.ResetCamera()
>         image_renderer.GetActiveCamera().ParallelProjectionOn()
>         self.render_window().AddRenderer(image_renderer)
>
>         self.set_orientation('AXIAL')
>         self.render()



More information about the vtkusers mailing list