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

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.

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 and the description here.

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.

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 :slightly_smiling_face:

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.

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

  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. :slightly_smiling_face:

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?

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

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.

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 :slightly_smiling_face:

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 and if there is anything that you can’t find then you can ask on the Slicer forum.