Here is my code to display 2d slices of DICOM volume using vtk renderer with python :
# Read DICOM images
self.reader = vtk.vtkDICOMImageReader()
self.reader.SetDirectoryName(folder)
self.reader.Update()
#Create Sagittal Slice Matrix
sagittal = vtk.vtkMatrix4x4()
sagittal.DeepCopy((0, 0, -1, center[0],
1, 0, 0, center[1],
0, -1, 0, center[2],
0, 0, 0, 1))
# Reslice image
widget = QVTKRenderWindowInteractor()
slice = vtk.vtkImageReslice()
slice.SetInputConnection(self.reader.GetOutputPort())
slice.SetOutputDimensionality(2)
slice.SetResliceAxes(sagittal)
slice.SetInterpolationModeToLinear()
# Display the image
actor = vtk.vtkImageActor()
actor.GetMapper().SetInputConnection(slice.GetOutputPort())
renderer = vtk.vtkRenderer()
# Remove Renderer And Reset
renderer.RemoveAllViewProps()
renderer.ResetCamera()
widget.GetRenderWindow().Render()
renderer.AddActor(actor)
widget.GetRenderWindow().AddRenderer(renderer)
# Set up the interaction
slice_interactorStyle = vtk.vtkInteractorStyleImage()
slice_interactor = widget.GetRenderWindow().GetInteractor()
slice_interactor.SetInteractorStyle(slice_interactorStyle)
widget.GetRenderWindow().SetInteractor(slice_interactor)
widget.GetRenderWindow().Render()
# Start interaction
slice_interactor.Start()
This is also my output :
dgobbi
(David Gobbi)
September 30, 2019, 8:17pm
#2
The vtkImageProperty can be used to adjust the contrast. For a 16 bit CT you can use the following as a starting point:
actor.GetProperty().SetLevel(0.0)
actor.GetProperty().SetWindow(2000.0)
2 Likes
Woooow !!
incredible
This is exactly what I wanted
Thank You very much for your answering
could you please explain a little about color window and color level ?
what are they changing and effecting on?
dgobbi
(David Gobbi)
October 1, 2019, 5:04pm
#5
VTK’s “ColorWindow” and “ColorLevel” correspond to what radiologists usually call the “window level” and “window width”, e.g.:
Windowing, also known as grey-level mapping, contrast stretching, histogram modification or contrast enhancement is the process in which the CT image greyscale component of an image is manipulated via the CT numbers; doing this will change the ap...
To make a long story short, the image mapper has a lookup table (grayscale by default), and the ColorWindow and ColorLevel in the image property control the range of image values that are mapped through the lookup table.
for volume is it also the same way or is different?
dgobbi
(David Gobbi)
October 1, 2019, 5:15pm
#8
You mean volume rendering, i.e. vtkVolumeProperty? Completely different.
Yes, vtkVolumeProperty
I mean for adjusting the volume contrast too what should I do?
as you see my volume has lots of noise too.
as I searched , only understand that I have to use vtkPiecewiseFunction with vtkVolumeProperty.setColor()
but I’m not sure about t it
I’m first in vtk.
dgobbi
(David Gobbi)
October 1, 2019, 5:28pm
#11
Thank you so much for all your helpful responses.
Amirof
(Amir Hossein)
May 1, 2020, 8:18pm
#14
I have exactly similar project but I am new to python. I need to ask some basics. How can I contact with you?
Im working on a same project but on pelvis. I need to add implant to some pictures and move them to find the best position. Since last time I messaged I had succeeded a lot. Do you find any way to make a 3D stl file from CT-Images?
flaviu2
August 11, 2020, 10:05am
#18