[vtkusers] Set window/level and convert image DICOM

David Gobbi david.gobbi at gmail.com
Fri Jan 22 13:40:41 EST 2016


Hi Pedro,

I think that I misunderstood your question.  Do you want to apply the preset
WindowCenter and WindowWidth that are stored in the DICOM meta data?
Or do you want to compute your own window and level?

 - David


On Thu, Jan 21, 2016 at 11:46 PM, Pedro Paulo <pedropaulobmjr at hotmail.com>
wrote:

> I'm using python to do this, my code is below, how do I add your code in
> mine to give right?
>
> Does your vtk-dicom package set the parameters ww/wl and do the conversion?
>
> Sorry my bad english. [image: &#X1f60a]
>
>
>
> from vtk import *
>
> reader = vtkDICOMImageReader()
> reader.SetFileName('image.dcm')
> reader.Update()
> image = reader.GetOutput()
>
> shiftScaleFilter = vtkImageShiftScale()
> shiftScaleFilter.SetOutputScalarTypeToUnsignedChar()
> shiftScaleFilter.SetInputConnection(reader.GetOutputPort())
>
> shiftScaleFilter.SetShift(-1.0*image.GetScalarRange()[0])
> oldRange = image.GetScalarRange()[1] - image.GetScalarRange()[0]
> newRange = 255
>
> shiftScaleFilter.SetScale(newRange/oldRange)
> shiftScaleFilter.Update()
>
> writer = vtkPNGWriter()
> writer.SetFileName('output.jpg')
> writer.SetInputConnection(shiftScaleFilter.GetOutputPort())
> writer.Write()
>
>
>
> ------------------------------
> *De:* David Gobbi <david.gobbi at gmail.com>
> *Enviado:* quinta-feira, 21 de janeiro de 2016 22:00
> *Para:* Pedro Paulo
> *Cc:* vtkusers at vtk.org
> *Assunto:* Re: [vtkusers] Set window/level and convert image DICOM
>
> Just to clarify my previous email, all CT and PET DICOM images have
> RescaleIntercept/RescaleSlope, but for CT, it is not uncommon to have
> RescaleIntercept = 0 and RescaleSlope = 1.  In any case, these fields
> cannot be ignored if you plan to use WindowCenter and WindowWidth.
>
> On Thu, Jan 21, 2016 at 2:47 PM, David Gobbi <david.gobbi at gmail.com>
> wrote:
>
>> Hi Pedro,
>>
>> I recommend using vtkImageMapToColors to apply a greyscale lookup table.
>> In python, for example, it would look like this:
>>
>> from vtk import *
>>
>> greymap = vtkScalarsToColors()
>> greymap.SetRange(wl - 0.5*ww, wl + 0.5*ww)
>>
>> applymap = vtkImageMapToColors()
>> applymap.SetInputConnection(...)
>> applymap.SetLookupTable(greymap)
>> applymap.SetOutputFormatToRGB() # or use SetOutputFormatToLuminance()
>> applymap.Update()
>>
>> Be careful, though, because according to the DICOM standard the
>> VOI LUT (i.e. window/level) should only be applied after the Modality LUT
>> (i.e. the RescaleIntercept/RescaleSlope).  Probably around half of the
>> CT images and nearly all PET images have RescaleIntercept/RescaleSlope,
>> so if you do not take these into account, you'll get an incorrect
>> result.  You'd
>> be safe with MRI, which does not have RescaleIntercept/Slope.
>>
>> So, of course, I'd suggest that you use my vtk-dicom package ;-)
>> https://github.com/dgobbi/vtk-dicom
>> It has a filter called vtkDICOMApplyRescale that will correctly apply the
>> rescale information.
>>
>>  - David
>>
>>
>> On Thu, Jan 21, 2016 at 2:22 PM, Pedro Paulo <pedropaulobmjr at hotmail.com>
>> wrote:
>>
>>> 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?
>>> Thanks!
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160122/29450fd2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OutlookEmoji-&#X1f60a.png
Type: image/png
Size: 488 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160122/29450fd2/attachment.png>


More information about the vtkusers mailing list