# Trying to render a series of dicom images belongs to MRI and Fluorescence but i am getting just white screen

**URL:** https://discourse.vtk.org/t/trying-to-render-a-series-of-dicom-images-belongs-to-mri-and-fluorescence-but-i-am-getting-just-white-screen/4338
**Category:** Support
**Created:** [October 2, 2020, 11:23am UTC](https://discourse.vtk.org/t/trying-to-render-a-series-of-dicom-images-belongs-to-mri-and-fluorescence-but-i-am-getting-just-white-screen/4338 "2020-10-02T11:23:48Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Yuvi-416](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yuvi-416/32/3864_2.png) [@Yuvi-416](https://discourse.vtk.org/u/Yuvi-416)
#### Post date: [October 2, 2020, 11:23am UTC](https://discourse.vtk.org/t/trying-to-render-a-series-of-dicom-images-belongs-to-mri-and-fluorescence-but-i-am-getting-just-white-screen/4338/1 "2020-10-02T11:23:48Z")

</div>

Hello there,  
I wrote a simple program to render a series of dicom images and it shows a good result for a CT images (exp: CT.dcm) but when i run the same code for series of MRI (MRI.dcm) or Fluorescence (F.dcm) images, i just get white screen. Can anyone suggest me what am i doing wrong?  
Size of images are CT : 512 x512, MRI = 192x192, F = 1316x1316  
CODE:  
import vtk  
from vtk.tk.vtkTkRenderWindowInteractor import vtkTkRenderWindowInteractor

input\_In = “/Users/Desktop/Temporary\_files/Rough-1/Temp/output1/Channel\_CZI-0/”

# # Load the dataset

reader = vtk.vtkDICOMImageReader()  
reader.SetDirectoryName(input\_In)  
reader.Update()

opacityTransferFunction = vtk.vtkPiecewiseFunction()  
opacityTransferFunction.AddPoint(1, 0.0)  
opacityTransferFunction.AddPoint(100, 0.1)  
opacityTransferFunction.AddPoint(255, 1.0)

colorTransferFunction = vtk.vtkColorTransferFunction()  
colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0)  
colorTransferFunction.AddRGBPoint(64.0, 1.0, 0.0, 0.0)  
colorTransferFunction.AddRGBPoint(128.0, 0.0, 0.0, 1.0)  
colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0)  
colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0)

volumeProperty = vtk.vtkVolumeProperty()  
volumeProperty.SetColor(colorTransferFunction)  
volumeProperty.SetScalarOpacity(opacityTransferFunction)

# volumeProperty.ShadeOn()

volumeProperty.SetInterpolationTypeToLinear()

# = vtk.vtkVolumeRayCastCompositeFunction()

volumeMapper = vtk.vtkFixedPointVolumeRayCastMapper()  
volumeMapper.SetInputConnection(reader.GetOutputPort())

volume = vtk.vtkVolume()  
volume.SetMapper(volumeMapper)  
volume.SetProperty(volumeProperty)

ren = vtk.vtkRenderer()  
renWin = vtk.vtkRenderWindow()  
renWin.AddRenderer(ren)  
renWin.SetSize(1500, 1500)

# iren = vtkTkRenderWindowInteractor(self.root, rw=renWin, width=640, height=480)

# iren.Initialize()

ren.AddVolume(volume)  
ren.SetBackground(1, 1, 1)

renWin.Render()

# Instantiate necessary classes and create VTK pipeline

# rw = vtk.vtkRenderWindow()

# rw.SetSize(1500, 1500)

iren = vtk.vtkRenderWindowInteractor()  
iren.SetRenderWindow(renWin)  
iren.Initialize()  
iren.Start()

As a newbie, I can´t upload an image.  
Please help me on this topic.

---

<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 2, 2020, 2:31pm UTC](https://discourse.vtk.org/t/trying-to-render-a-series-of-dicom-images-belongs-to-mri-and-fluorescence-but-i-am-getting-just-white-screen/4338/2 "2020-10-02T14:31:57Z")

</div>

First, I would like to say that it is exciting to see someone successfully using the vtkTkRenderWindowInteractor in 2020. Which version of VTK are you using?

If you are trying to display a single image (rather than a stack of images), then vtkFixedPointVolumeRayCastMapper might not be the best choice. If it shows the slice at all, it will not show it properly.

A better option for showing slices or single images is to use vtkImageSlice and vtkImageSliceMapper instead of vtkVolume and a vtkVolumeMapper. See the example [here](https://lorensen.github.io/VTKExamples/site/Cxx/Images/ImageRotate/) and the description [here](https://vtk.org/Wiki/VTK/Image_Rendering_Classes).

It is also important to know the range of data values that you want to display. Your color transfer function is set exclusively to display values in the range [0,255] but medical images often use larger ranges like [0,1023] or [0,4095] or [-1024,2047]. Especially in the case of MR, the range must be tuned for each image.

---

<div class="post-metadata">

### Author: ![Yuvi-416](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yuvi-416/32/3864_2.png) [@Yuvi-416](https://discourse.vtk.org/u/Yuvi-416)
#### Post date: [October 2, 2020, 4:00pm UTC](https://discourse.vtk.org/t/trying-to-render-a-series-of-dicom-images-belongs-to-mri-and-fluorescence-but-i-am-getting-just-white-screen/4338/3 "2020-10-02T16:00:07Z")

</div>

Hello there,  
Thanks for your quick reply.  
I am using VTK 8.2.0 and ITK as 5.1.1.  
I am trying to visualize a series of DICOM images or you can say a stack of Dicom images. My goal is to perform 3D reconstruction.  
I understand your suggestion and I will follow it and let you know the output.  
But I would like to ask you, do you any other suggestion regarding it? My ultimate goal is to perform 3D reconstruction to these series of 2D Dicom image.  
Any advice of you might be helpful to me 🙂

---

<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 2, 2020, 4:07pm UTC](https://discourse.vtk.org/t/trying-to-render-a-series-of-dicom-images-belongs-to-mri-and-fluorescence-but-i-am-getting-just-white-screen/4338/4 "2020-10-02T16:07:43Z")

</div>

3D reconstruction is a very broad topic. You would have to more specific, and give an example of what you want the result to look like.

---

<div class="post-metadata">

### Author: ![Yuvi-416](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yuvi-416/32/3864_2.png) [@Yuvi-416](https://discourse.vtk.org/u/Yuvi-416)
#### Post date: [October 2, 2020, 4:47pm UTC](https://discourse.vtk.org/t/trying-to-render-a-series-of-dicom-images-belongs-to-mri-and-fluorescence-but-i-am-getting-just-white-screen/4338/5 "2020-10-02T16:47:58Z")

</div>

Hi there,  
I have a series of fluorescence images of some organism (like from 0-119 per group) and all these images are in a standard Dicom format. You can click this link to visualize the sample DCM image and as well as my requirement output in as in name 3D sample 1 and 2 ([https://www.dropbox.com/t/2tbrce36NVLDBnGk](https://www.dropbox.com/t/2tbrce36NVLDBnGk)).

1. My goal is to stack a series of 2D Dicom image into one and visualize it (I don´t want to save it in a .nii or anything, just want to visualize the stacked 2D image into 3D) in 3D format (like a 3D volume rendering). I want my output to be as like that 3D sample 1 and 2 output. 🙂

---

<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 2, 2020, 5:04pm UTC](https://discourse.vtk.org/t/trying-to-render-a-series-of-dicom-images-belongs-to-mri-and-fluorescence-but-i-am-getting-just-white-screen/4338/6 "2020-10-02T17:04:34Z")

</div>

From the examples, what you want is definitely volume rendering.

I think the first things you need to work on are the color transfer function and the opacity transfer functions. These have to be set differently for each kind of image, and creating a good color transfer function can be a very complex problem. Have you used the color transfer function editors in Slicer or in Paraview?

---

<div class="post-metadata">

### Author: ![Yuvi-416](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yuvi-416/32/3864_2.png) [@Yuvi-416](https://discourse.vtk.org/u/Yuvi-416)
#### Post date: [October 2, 2020, 10:37pm UTC](https://discourse.vtk.org/t/trying-to-render-a-series-of-dicom-images-belongs-to-mri-and-fluorescence-but-i-am-getting-just-white-screen/4338/7 "2020-10-02T22:37:46Z")

</div>

Hi,  
sorry for the late reply.  
As per your suggestion, I downloaded the 3D slicer and I try to load a series of Dicom data and I also try to visualize it in a 3D using volume rendering. I found the desired output by utilizing these parameters.  
**Display** : CT-Coronary-Arteries-2  
**Interpolation** : Linear  
**Material:** Ambient: 0.27, Diffuse: 0.80, Specular: 0.10, and Power as 1.0  
**Shift transfer function** : -140 to 20  
**Scalar opacity mapping** : At Point 0: x = -2188, O = 0.10, At Point 1; x = 22.68, O = 0.0, At Point 2; x = 25.02, O = 0.12, At Point 3; x = 72.17, O = 0.56, At Point 4; x = 97.24, O = 0.72, At Point 5; x = 264.65, O = 0.83, At Point 6; x = 3541, O = 0.83  
**Scalar color mapping** : At Point 0: x = -2188, #000000, At Point 1; x = 22.68,#000000, At Point 2; x = 25.02, #9d0004, At Point 3; x = 72.17, #e87400, At Point 4; x = 97.24, #f8ce9c, At Point 5; x = 264.65, #e8e8ff, At Point 6; x = 3541, #ffffff  
**Gradient Opacity** : At point 0: x = -120, O=1, At point 1: x = 135, O = 1  
These are the parameter´s which I found over there.  
So, now what should I do?  
🙂

---

<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: [October 3, 2020, 4:08am UTC](https://discourse.vtk.org/t/trying-to-render-a-series-of-dicom-images-belongs-to-mri-and-fluorescence-but-i-am-getting-just-white-screen/4338/8 "2020-10-03T04:08:10Z")

</div>

It is great to hear that you could achieve the visualization that you wanted using 3D Slicer. Now you need to decide if you want to spend your time with redeveloping and maintaining visualization features from scratch; or you take what Slicer offers (and maybe extend/customize it to make it very easy to use) and use the time that you save on progressing with your project faster.

---

<div class="post-metadata">

### Author: ![Yuvi-416](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yuvi-416/32/3864_2.png) [@Yuvi-416](https://discourse.vtk.org/u/Yuvi-416)
#### Post date: [October 3, 2020, 9:13am UTC](https://discourse.vtk.org/t/trying-to-render-a-series-of-dicom-images-belongs-to-mri-and-fluorescence-but-i-am-getting-just-white-screen/4338/9 "2020-10-03T09:13:45Z")

</div>

Hello, thanks for the reply.  
Yeah, I got the desired output by utilizing 3D slicer but my goal is to build a 3D volume rendering toolbox from this particular series of Dicom images. So, what are the steps I have to look after to build it in python?  
Any suggestion might be helpful 🙂

---

<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: [October 3, 2020, 12:42pm UTC](https://discourse.vtk.org/t/trying-to-render-a-series-of-dicom-images-belongs-to-mri-and-fluorescence-but-i-am-getting-just-white-screen/4338/10 "2020-10-03T12:42:11Z")

</div>

In Slicer’s Python environment, it takes about 10-15 lines of code to load your input volumes from DICOM files and visualization settings from the saved scene file. You can find lots of examples [here](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository) and if there is anything that you can’t find then you can ask on the [Slicer forum](https://discourse.slicer.org).
