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