[vtkusers] differences in window/level
José M. Rodriguez Bacallao
jmrbcu at gmail.com
Mon Dec 17 16:34:25 EST 2012
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()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121217/6cb2b372/attachment.htm>
More information about the vtkusers
mailing list