<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p></p>
<div>Yeah, I used with version 6 and functioned normally, thank you, do you know how I could do these operations of window/level using my code?</div>
<div>It is the last feature of my software and I have no idea how to do it.</div>
<p></p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>De:</b> David Gobbi <david.gobbi@gmail.com><br>
<b>Enviado:</b> sexta-feira, 22 de janeiro de 2016 19:22<br>
<b>Para:</b> Pedro Paulo<br>
<b>Cc:</b> vtkusers@vtk.org<br>
<b>Assunto:</b> Re: [vtkusers] Set window/level and convert image DICOM</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hi Pedro,
<div><br>
</div>
<div>If you get that error with vtkScalarsToColors, then your VTK is very old!</div>
<div>To use vtkScalarsToColors like this, you must use vtk 5.10, vtk 6, or vtk 7.</div>
<div><br>
</div>
<div>Maybe you should keep your original code, with vtkImageShiftScale.</div>
<div>The math to convert from "range" to "shift/scale" is shown on this page:</div>
<div><a href="http://www.cognitive-antics.net/mw/index.php?title=Data_range_remapping" id="LPlnk881286">http://www.cognitive-antics.net/mw/index.php?title=Data_range_remapping</a><br>
</div>
<div><br>
</div>
<div> - David</div>
<div><br>
</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Jan 22, 2016 at 12:11 PM, Pedro Paulo <span dir="ltr">
<<a href="mailto:pedropaulobmjr@hotmail.com" target="_blank">pedropaulobmjr@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">
<div style="font-size:12pt; color:#000000; background-color:#ffffff; font-family:Calibri,Arial,Helvetica,sans-serif">
<p></p>
<div>I would like to set the WindowCenter and WindowWidth with which the image is converted to png, when I do the conversion using the program I sent, it makes the window and <span style="font-family:Calibri,Arial,Helvetica,sans-serif,'Apple Color Emoji','Segoe UI Emoji',NotoColorEmoji,'Segoe UI Symbol','Android Emoji',EmojiSymbols; font-size:16px">level </span>automatically,
 which I do not want it to do. For your second question, yes, I want to calculate my own window and level when I convert the image.</div>
<div>For example, I want to make a conversion with the values ww=2000, wl=250 and at another time to make a conversion into the same image with the values ww=3000, wl=150.</div>
<div><br>
</div>
<div><br>
</div>
<div>I tried using your code like this:</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div>from vtk import *</div>
<div><br>
</div>
<div>reader = vtkDICOMImageReader()</div>
<div>reader.SetFileName("img.dcm")</div>
<div>reader.Update()</div>
<div>image = reader.GetOutput()</div>
<div><br>
</div>
<div>###########################################################</div>
<div>ww = 2500</div>
<div>wl = 200</div>
<div><br>
</div>
<div>greymap = vtkScalarsToColors()</div>
<div>greymap.SetRange(wl-0.5*ww, wl+0.5*ww)</div>
<div><br>
</div>
<div>applymap = vtkImageMapToColors()</div>
<div>applymap.SetInputConnection(reader.GetOutputPort())</div>
<div>applymap.SetLookupTable(greymap)</div>
<div><br>
</div>
<div><span style="font-size:12pt">applymap.SetOutputFormatToRGB()</span><br>
</div>
<div>applymap.Update()</div>
<div>###########################################################</div>
</div>
<div></div>
<div><br>
</div>
<div>and I got the following error:</div>
<div><br>
</div>
<div>Traceback (most recent call last):</div>
<div>  File "ff.py", line 12, in <module></div>
<div>    greymap = vtkScalarsToColors ()</div>
<div>TypeError: this is an abstract class and can not be instantiated</div>
<br>
<p></p>
<br>
<br>
<div style="color:rgb(0,0,0)">
<hr style="display:inline-block; width:98%">
<div dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>De:</b> David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>><br>
<b>Enviado:</b> sexta-feira, 22 de janeiro de 2016 18:40
<div>
<div class="h5"><br>
<b>Para:</b> Pedro Paulo<br>
<b>Cc:</b> <a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a><br>
<b>Assunto:</b> Re: [vtkusers] Set window/level and convert image DICOM</div>
</div>
</font>
<div> </div>
</div>
<div>
<div class="h5">
<div>
<div dir="ltr">Hi Pedro,
<div><br>
</div>
<div>I think that I misunderstood your question.  Do you want to apply the preset</div>
<div>WindowCenter and WindowWidth that are stored in the DICOM meta data?</div>
<div>Or do you want to compute your own window and level?</div>
<div><br>
</div>
<div> - David</div>
<div><br>
</div>
<div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Jan 21, 2016 at 11:46 PM, Pedro Paulo <span dir="ltr">
<<a href="mailto:pedropaulobmjr@hotmail.com" target="_blank">pedropaulobmjr@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">
<div style="font-size:12pt; color:#000000; background-color:#ffffff; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>I'm using python to do this, my code is below, how do I add your code in mine to give right?<br>
</p>
<p>Does your vtk-dicom package set the parameters ww/wl and do the conversion?<br>
</p>
<p>Sorry my bad english. <img alt="&#X1f60a" style="vertical-align: bottom; -webkit-user-select: none;" tabindex="0" src="cid:42cfd0e3-b39d-41f6-ace2-27c3c6f7d905"><br>
</p>
<p><br>
</p>
<p><br>
</p>
<div>from vtk import *</div>
<div><br>
</div>
<div>reader = vtkDICOMImageReader()</div>
<div>reader.SetFileName('image.dcm')</div>
<div>reader.Update()</div>
<div>image = reader.GetOutput()</div>
<div><br>
</div>
<div>shiftScaleFilter = vtkImageShiftScale()</div>
<div>shiftScaleFilter.SetOutputScalarTypeToUnsignedChar()</div>
<div>shiftScaleFilter.SetInputConnection(reader.GetOutputPort())</div>
<div><br>
</div>
<div>shiftScaleFilter.SetShift(-1.0*image.GetScalarRange()[0])</div>
<div>oldRange = image.GetScalarRange()[1] - image.GetScalarRange()[0]</div>
<div>newRange = 255</div>
<div><br>
</div>
<div>shiftScaleFilter.SetScale(newRange/oldRange)</div>
<div>shiftScaleFilter.Update()</div>
<div><br>
</div>
<div>writer = vtkPNGWriter()</div>
<div>writer.SetFileName('output.jpg')</div>
<div>writer.SetInputConnection(shiftScaleFilter.GetOutputPort())</div>
<div>writer.Write()</div>
<div><br>
</div>
<br>
<br>
<div style="color:rgb(0,0,0)">
<hr style="display:inline-block; width:98%">
<div dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>De:</b> David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>><br>
<b>Enviado:</b> quinta-feira, 21 de janeiro de 2016 22:00<br>
<b>Para:</b> Pedro Paulo<br>
<b>Cc:</b> <a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a><br>
<b>Assunto:</b> Re: [vtkusers] Set window/level and convert image DICOM</font>
<div> </div>
</div>
<div>
<div>
<div>
<div dir="ltr">Just to clarify my previous email, all CT and PET DICOM images have
<div>RescaleIntercept/RescaleSlope, but for CT, it is not uncommon to have</div>
<div>RescaleIntercept = 0 and RescaleSlope = 1.  In any case, these fields</div>
<div>cannot be ignored if you plan to use WindowCenter and WindowWidth.</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Jan 21, 2016 at 2:47 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">
<div dir="ltr">Hi Pedro,
<div><br>
</div>
<div>I recommend using vtkImageMapToColors to apply a greyscale lookup table.</div>
<div>In python, for example, it would look like this:</div>
<div><br>
</div>
<div>from vtk import *</div>
<div><br>
</div>
<div>greymap = vtkScalarsToColors()</div>
<div>greymap.SetRange(wl - 0.5*ww, wl + 0.5*ww)</div>
<div><br>
</div>
<div>applymap = vtkImageMapToColors()</div>
<div>applymap.SetInputConnection(...)</div>
<div>applymap.SetLookupTable(greymap)</div>
<div>applymap.SetOutputFormatToRGB() # or use SetOutputFormatToLuminance()</div>
<div>applymap.Update()</div>
<div><br>
</div>
<div>Be careful, though, because according to the DICOM standard the</div>
<div>VOI LUT (i.e. window/level) should only be applied after the Modality LUT</div>
<div>(i.e. the RescaleIntercept/RescaleSlope).  Probably around half of the</div>
<div>CT images and nearly all PET images have RescaleIntercept/RescaleSlope,</div>
<div>so if you do not take these into account, you'll get an incorrect result.  You'd</div>
<div>be safe with MRI, which does not have RescaleIntercept/Slope.</div>
<div><br>
</div>
<div>So, of course, I'd suggest that you use my vtk-dicom package ;-)</div>
<div><a href="https://github.com/dgobbi/vtk-dicom" title="https://github.com/dgobbi/vtk-dicom
Ctrl+Clique ou toque para seguir o link" target="_blank">https://github.com/dgobbi/vtk-dicom</a><br>
</div>
<div>It has a filter called vtkDICOMApplyRescale that will correctly apply the</div>
<div>rescale information.</div>
<span><font color="#888888">
<div><br>
</div>
<div> - David</div>
</font></span><span>
<div><br>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Jan 21, 2016 at 2:22 PM, Pedro Paulo <span dir="ltr">
<<a href="mailto:pedropaulobmjr@hotmail.com" target="_blank">pedropaulobmjr@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-color:rgb(204,204,204); border-left-style:solid; padding-left:1ex">
<div dir="ltr">
<div style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; background-color:rgb(255,255,255)">
<p></p>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px">Hi people, I want to convert a DICOM image to a png, but, before converting, I would like to set the parameters of Window Width and Window Center, to that the png image looks like if
 the parameters of ww/wl were seen in a viewer, does anyone know how could I do this?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px">Thanks!</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</span></div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</body>
</html>