<div dir="ltr">thanks david, I understand what you mean and this apply to tow path of the pipeline: <div><br></div><div><span style="font-family:arial,sans-serif;font-size:12.727272033691406px"> format in (vtkgdcm.VTK_LOOKUP_TABLE, vtkgdcm.VTK_INVERSE_LUMINANCE) and</span><br>
</div><div><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">format == vtkgdcm.VTK_YBR</span><span style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br>
</span></div><div style><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">but the format of the image I am displaying is: </span><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">VTK_LUMINANCE so, it goes for this path:</span></div>
<div style><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">else:</div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px"> scalar_range = vtk_image.GetScalarRange()</div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">
image_mapper.SetInput(vtk_image)</div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">so, there is no vtkImageMapToColors involved, just the vtkImageProperty and the image is dark with this path</div>
<div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">any suggestions?</div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">also, when the image format type is VTK_LOOKUP_TABLE, if I only use vtkImageProperty and set the property lookup table to the lookup table of the image, the colors of the displayed image are wrong.</div>
</div><div style><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Dec 17, 2012 at 5:24 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Your image is dark because you are applying the window/level<br>
_after_ you have converted the image to RGB. After the image<br>
is RGB, it has values in the range [0,255]. So of course if you<br>
apply a window/level of 1995/998 to such an image, the result<br>
is going to be very dark.<br>
<br>
To summarize: you can apply the window/level with<br>
vtkImageMapToColors, or you can apply the window/level<br>
with vtkImageProperty, but _not with both_.<br>
<br>
Two ways to fix:<br>
<br>
<br>
Option #1: Apply window/level with vtkImageMapToColors<br>
<br>
lut.SetRange(level-0.5*window, level+0.5*window)<br>
image_property.SetColorWindow(255.0)<br>
image_property.SetColorLevel(127.5)<br>
<br>
<br>
Option #2: Apply window/level with vtkImageProperty:<br>
<br>
Remove vtkImageMapToColors from your pipeline (completely!)<br>
image_property.SetColorWindow(window)<br>
image_property.SetColorLevel(level)<br>
image_property.SetLookupTable(lut) # optional<br>
<span class="HOEnZb"><font color="#888888"><br>
- David<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
On Mon, Dec 17, 2012 at 2:48 PM, José M. Rodriguez Bacallao<br>
<<a href="mailto:jmrbcu@gmail.com">jmrbcu@gmail.com</a>> wrote:<br>
> sorry, the attachment was a little big so I had to scale it down, here is<br>
> again:<br>
><br>
> hello, while I was testing a dicom viewer I am developing I noticed<br>
> differences in window leveling from the pipeline I am using with respect to<br>
> one of the viewers I use as reference. I attached the snapshot, the left<br>
> window is my viewer and the right is one of my reference viewers. Both have<br>
> the same window/level: 1995/998, but the image displayed at left is darker<br>
> than right, here is part of the pipeline I use:<br>
><br>
> vtk_image = image.vtk_image<br>
> self.view = vtk.QVTKWidget(self)<br>
> self.view.setFocusProxy(self)<br>
> # add the view to the internal layout<br>
> self.setUpdatesEnabled(False)<br>
> self.layout().takeAt(1)<br>
> self.layout().addWidget(self.view)<br>
> self.setUpdatesEnabled(True)<br>
><br>
> # create the main interactor style<br>
> style = vtk.vtkInteractorStyleImage()<br>
> style.SetInteractionModeToImageSlicing()<br>
><br>
> self.view.GetRenderWindow().GetInteractor().SetInteractorStyle(style)<br>
><br>
> # the axial orientation<br>
> style.SetZViewRightVector((1, 0, 0))<br>
> style.SetZViewUpVector((0, -1, 0))<br>
><br>
> # the sagital orientation<br>
> style.SetXViewRightVector((0, 1, 0))<br>
> style.SetXViewUpVector((0, 0, 1))<br>
><br>
> # the coronal orientation<br>
> style.SetYViewRightVector((1, 0, 0))<br>
> style.SetYViewUpVector((0, 0, 1))<br>
><br>
> image_mapper = vtk.vtkImageResliceMapper()<br>
> image_mapper.SliceFacesCameraOn()<br>
> image_mapper.SliceAtFocalPointOn()<br>
> image_mapper.JumpToNearestSliceOn()<br>
> image_mapper.BorderOff()<br>
> self.image_mapper = image_mapper<br>
><br>
> format = image.image_format<br>
> if format in (vtkgdcm.VTK_LOOKUP_TABLE,<br>
> vtkgdcm.VTK_INVERSE_LUMINANCE):<br>
> lut = vtk_image.GetPointData().GetScalars().GetLookupTable()<br>
><br>
> if isinstance(lut, vtkgdcm.vtkLookupTable16):<br>
> color_filter = vtkgdcm.vtkImageMapToColors16()<br>
> else:<br>
> color_filter = vtk.vtkImageMapToColors()<br>
><br>
> color_filter.SetInputConnection(vtk_image.GetProducerPort())<br>
> color_filter.SetLookupTable(lut)<br>
><br>
> if format == vtkgdcm.VTK_LOOKUP_TABLE:<br>
> color_filter.SetOutputFormatToRGB()<br>
> elif format == vtkgdcm.VTK_INVERSE_LUMINANCE:<br>
> color_filter.SetOutputFormatToLuminance()<br>
><br>
> color_filter.Update()<br>
> scalar_range = color_filter.GetOutput().GetScalarRange()<br>
> image_mapper.SetInputConnection(color_filter.GetOutputPort())<br>
> del color_filter<br>
> elif format == vtkgdcm.VTK_YBR:<br>
> color_filter = vtkgdcm.vtkImageYBRToRGB()<br>
> color_filter.SetInputConnection(vtk_image.GetProducerPort())<br>
> color_filter.Update()<br>
> scalar_range = color_filter.GetOutput().GetScalarRange()<br>
> image_mapper.SetInputConnection(color_filter.GetOutputPort())<br>
> del color_filter<br>
> else:<br>
> scalar_range = vtk_image.GetScalarRange()<br>
> image_mapper.SetInput(vtk_image)<br>
><br>
> try:<br>
> # here the window width will be: 1995 and window level: 998<br>
> level = image.window_level[0]<br>
> window = image.window_width[0]<br>
> except KeyError, IndexError:<br>
> window = scalar_range[1] - scalar_range[0]<br>
> level = 0.5 * (scalar_range[1] + scalar_range[0])<br>
><br>
> image_property = vtk.vtkImageProperty()<br>
> image_property.SetColorWindow(window)<br>
> image_property.SetColorLevel(level)<br>
> image_property.SetAmbient(0.0)<br>
> image_property.SetDiffuse(1.0)<br>
> image_property.SetOpacity(1.0)<br>
> image_property.SetInterpolationTypeToLinear()<br>
> self.image_property = image_property<br>
><br>
> image_actor = vtk.vtkImageSlice()<br>
> image_actor.SetMapper(image_mapper)<br>
> image_actor.SetProperty(image_property)<br>
> self.image_actor = image_actor<br>
><br>
> image_renderer = vtk.vtkRenderer()<br>
> image_renderer.SetBackground(0, 0, 0)<br>
> self.image_renderer = image_renderer<br>
> image_renderer.AddViewProp(image_actor)<br>
> image_renderer.ResetCamera()<br>
> image_renderer.GetActiveCamera().ParallelProjectionOn()<br>
> self.render_window().AddRenderer(image_renderer)<br>
><br>
> self.set_orientation('AXIAL')<br>
> self.render()<br>
</div></div></blockquote></div><br></div>