How to improve noises of displaying 2D DICOM slices with rendering vtk and make it more clear ?

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 :

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 :slight_smile:
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?

VTK’s “ColorWindow” and “ColorLevel” correspond to what radiologists usually call the “window level” and “window width”, e.g.:

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?

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.

Here is an example with explanations:
https://lorensen.github.io/VTKExamples/site/Python/Medical/MedicalDemo4/

And the chapter in the VTK textbook (though it is out of date now):
https://lorensen.github.io/VTKExamples/site/VTKBook/07Chapter7/#73-volume-rendering

Thank you so much for all your helpful responses.:pray:

I have exactly similar project but I am new to python. I need to ask some basics. How can I contact with you?

You can message me here.

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?

I think you can use https://vtk.org/doc/nightly/html/classvtkSTLWriter.html for that. You can find here a little sample:https://vtk.org/Wiki/VTK/Examples/Cxx/IO/WriteSTL