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

**URL:** https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843
**Category:** Support
**Created:** [September 30, 2019, 11:22am UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843 "2019-09-30T11:22:42Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![kimia.af1998](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/7ab992/32.png) [@kimia.af1998](https://discourse.vtk.org/u/kimia.af1998)
#### Post date: [September 30, 2019, 11:22am UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/1 "2019-09-30T11:22:42Z")

</div>

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 :

 ![Screenshot%20from%202019-09-30%2014-47-05](https://discourse.vtk.org/uploads/default/original/1X/407727a5f3297f393fd73153c9d4705ab556ba78.jpeg)

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [September 30, 2019, 8:17pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/2 "2019-09-30T20:17:03Z")

</div>

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)
```

---

<div class="post-metadata">

### Author: ![kimia.af1998](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/7ab992/32.png) [@kimia.af1998](https://discourse.vtk.org/u/kimia.af1998)
#### Post date: [October 1, 2019, 4:03pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/3 "2019-10-01T16:03:17Z")

</div>

Woooow !!  
incredible  
This is exactly what I wanted 🙂  
Thank You very much for your answering

---

<div class="post-metadata">

### Author: ![kimia.af1998](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/7ab992/32.png) [@kimia.af1998](https://discourse.vtk.org/u/kimia.af1998)
#### Post date: [October 1, 2019, 4:34pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/4 "2019-10-01T16:34:11Z")

</div>

could you please explain a little about color window and color level ?  
what are they changing and effecting on?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 1, 2019, 5:04pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/5 "2019-10-01T17:04:05Z")

</div>

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

> **[Windowing (CT) | Radiology Reference Article | Radiopaedia.org](https://radiopaedia.org/articles/windowing-ct)**
>
> 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.

---

<div class="post-metadata">

### Author: ![kimia.af1998](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/7ab992/32.png) [@kimia.af1998](https://discourse.vtk.org/u/kimia.af1998)
#### Post date: [October 1, 2019, 5:13pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/7 "2019-10-01T17:13:13Z")

</div>

for volume is it also the same way or is different?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 1, 2019, 5:15pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/8 "2019-10-01T17:15:57Z")

</div>

You mean volume rendering, i.e. vtkVolumeProperty? Completely different.

---

<div class="post-metadata">

### Author: ![kimia.af1998](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/7ab992/32.png) [@kimia.af1998](https://discourse.vtk.org/u/kimia.af1998)
#### Post date: [October 1, 2019, 5:19pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/9 "2019-10-01T17:19:56Z")

</div>

Yes, vtkVolumeProperty  
I mean for adjusting the volume contrast too what should I do?  
as you see my volume has lots of noise too.

---

<div class="post-metadata">

### Author: ![kimia.af1998](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/7ab992/32.png) [@kimia.af1998](https://discourse.vtk.org/u/kimia.af1998)
#### Post date: [October 1, 2019, 5:24pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/10 "2019-10-01T17:24:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 1, 2019, 5:28pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/11 "2019-10-01T17:28:05Z")

</div>

Here is an example with explanations:  
[https://lorensen.github.io/VTKExamples/site/Python/Medical/MedicalDemo4/](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](https://lorensen.github.io/VTKExamples/site/VTKBook/07Chapter7/#73-volume-rendering)

---

<div class="post-metadata">

### Author: ![kimia.af1998](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/7ab992/32.png) [@kimia.af1998](https://discourse.vtk.org/u/kimia.af1998)
#### Post date: [October 1, 2019, 6:00pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/13 "2019-10-01T18:00:06Z")

</div>

Thank you so much for all your helpful responses.🙏

---

<div class="post-metadata">

### Author: ![Amirof](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/9de0a6/32.png) [@Amirof](https://discourse.vtk.org/u/Amirof)
#### Post date: [May 1, 2020, 8:18pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/14 "2020-05-01T20:18:26Z")

</div>

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

---

<div class="post-metadata">

### Author: ![kimia.af1998](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/7ab992/32.png) [@kimia.af1998](https://discourse.vtk.org/u/kimia.af1998)
#### Post date: [May 19, 2020, 6:35am UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/16 "2020-05-19T06:35:07Z")

</div>

You can message me here.

---

<div class="post-metadata">

### Author: ![Amir\_Hossein\_Zeydi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amir_hossein_zeydi/32/2161_2.png) [@Amir\_Hossein\_Zeydi](https://discourse.vtk.org/u/Amir_Hossein_Zeydi)
#### Post date: [August 4, 2020, 9:09am UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/17 "2020-08-04T09:09:02Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [August 11, 2020, 10:05am UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/18 "2020-08-11T10:05:28Z")

</div>

I think you can use [https://vtk.org/doc/nightly/html/classvtkSTLWriter.html](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](https://vtk.org/Wiki/VTK/Examples/Cxx/IO/WriteSTL)

---

<div class="post-metadata">

### Author: ![Nixaam\_LLC](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nixaam_llc/32/6387_2.png) [@Nixaam\_LLC](https://discourse.vtk.org/u/Nixaam_LLC)
#### Post date: [January 10, 2023, 12:04pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/19 "2023-01-10T12:04:28Z")

</div>

I am running the same code on by cbct dicom dataset, but output is not clear

 ![image](https://discourse.vtk.org/uploads/default/original/2X/0/05fcca46f9a7e9e7c8bb95c727194844207a5efd.jpeg)

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [January 13, 2023, 1:18pm UTC](https://discourse.vtk.org/t/how-to-improve-noises-of-displaying-2d-dicom-slices-with-rendering-vtk-and-make-it-more-clear/1843/20 "2023-01-13T13:18:37Z")

</div>

There are lots of noise filters and image enhancement filters in ITK, so you may consider posting this question to the [ITK forum](http://discourse.itk.org/). You will need to provide more details, at least screenshots, but preferably anonymized images; and a description of what you mean by “output is not clear” (from the image above it seems like it is a cone-beam CT and you have trouble with motion artifacts, but it is not obvious). Copy the link to your ITK post here so that people interested in this can follow follow the discussion there.
