[vtkusers] Set window/level and convert image DICOM
Pedro Paulo
pedropaulobmjr at hotmail.com
Fri Jan 22 16:44:24 EST 2016
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?
It is the last feature of my software and I have no idea how to do it.
________________________________
De: David Gobbi <david.gobbi at gmail.com>
Enviado: sexta-feira, 22 de janeiro de 2016 19:22
Para: Pedro Paulo
Cc: vtkusers at vtk.org
Assunto: Re: [vtkusers] Set window/level and convert image DICOM
Hi Pedro,
If you get that error with vtkScalarsToColors, then your VTK is very old!
To use vtkScalarsToColors like this, you must use vtk 5.10, vtk 6, or vtk 7.
Maybe you should keep your original code, with vtkImageShiftScale.
The math to convert from "range" to "shift/scale" is shown on this page:
http://www.cognitive-antics.net/mw/index.php?title=Data_range_remapping
- David
On Fri, Jan 22, 2016 at 12:11 PM, Pedro Paulo <pedropaulobmjr at hotmail.com<mailto:pedropaulobmjr at hotmail.com>> wrote:
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 level 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.
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.
I tried using your code like this:
from vtk import *
reader = vtkDICOMImageReader()
reader.SetFileName("img.dcm")
reader.Update()
image = reader.GetOutput()
###########################################################
ww = 2500
wl = 200
greymap = vtkScalarsToColors()
greymap.SetRange(wl-0.5*ww, wl+0.5*ww)
applymap = vtkImageMapToColors()
applymap.SetInputConnection(reader.GetOutputPort())
applymap.SetLookupTable(greymap)
applymap.SetOutputFormatToRGB()
applymap.Update()
###########################################################
and I got the following error:
Traceback (most recent call last):
File "ff.py", line 12, in <module>
greymap = vtkScalarsToColors ()
TypeError: this is an abstract class and can not be instantiated
________________________________
De: David Gobbi <david.gobbi at gmail.com<mailto:david.gobbi at gmail.com>>
Enviado: sexta-feira, 22 de janeiro de 2016 18:40
Para: Pedro Paulo
Cc: vtkusers at vtk.org<mailto:vtkusers at vtk.org>
Assunto: Re: [vtkusers] Set window/level and convert image DICOM
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<mailto: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. [😊]
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<mailto:david.gobbi at gmail.com>>
Enviado: quinta-feira, 21 de janeiro de 2016 22:00
Para: Pedro Paulo
Cc: vtkusers at vtk.org<mailto: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<mailto: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<mailto: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/499447df/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OutlookEmoji-😊.png
Type: image/png
Size: 488 bytes
Desc: OutlookEmoji-😊.png
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160122/499447df/attachment.png>
More information about the vtkusers
mailing list