Hello guys,
I am trying to visualize series of dicomized microscope LSM into 3D visualization using the VTK python package. I wrote the below code which works perfectly for the CT Dicom image but not for the LSM image. I also use ParaView to check the vtkColorTransferFunction and vtkPiecewiseFunction value. Even though I use the same values of vtkColorTransferFunction and vtkPiecewiseFunction as ParaView in python but it doesn’t show me the image beside the blue colour. And when I try to pass series of LSM Dicom images the viewer gets stuck and it shows a white screen.
Code:
import vtk
dir1 = "/home/yuvi/Desktop/Rough/inputs/output/"
dir = "/home/yuvi/Desktop/Rough/inputs/CT_dcm/"
reader = vtk.vtkDICOMImageReader()
reader.SetDirectoryName(dir1)
reader.Update()
imageData = reader.GetOutput()
scalar_range1 = imageData.GetScalarRange()
alphaChannelFunc = vtk.vtkPiecewiseFunction()
alphaChannelFunc.AddPoint(2, 0)
alphaChannelFunc.AddPoint(228, 1)
color = vtk.vtkColorTransferFunction()
color.AddRGBPoint(2, 0.231373, 0.298039, 0.752941)
color.AddRGBPoint(115, 0.865003, 0.865003, 0.865003)
color.AddRGBPoint(228, 0.705882, 0.0156863, 0.14902)
#############################################################################
volumeMapper = vtk.vtkGPUVolumeRayCastMapper()
volumeMapper.SetInputConnection(reader.GetOutputPort())
###########################################################################
volumeProperty = vtk.vtkVolumeProperty()
volumeProperty.ShadeOff()
volumeProperty.SetInterpolationType(vtk.VTK_LINEAR_INTERPOLATION)
volumeProperty.SetScalarOpacity(alphaChannelFunc)
volumeProperty.SetColor(color)
volume = vtk.vtkVolume()
volume.SetMapper(volumeMapper)
volume.SetProperty(volumeProperty)
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
ren1.AddVolume(volume)
ren1.SetBackground(1, 1, 1)
renWin.SetSize(800, 800)
def exitCheck(obj, event):
if obj.GetEventPending() != 0:
obj.SetAbortRender(1)
# Tell the application to use the function as an exit check.
renWin.AddObserver("AbortCheckEvent", exitCheck)
iren.Initialize()
renWin.Render()
iren.Start()
And here’s the Paraview values for vtkColorTransferFunction and vtkPiecewiseFunction:
And this the output when I pass CT image: which is perfect.
And when I pass just one single Dicom LSM image it shows me the below output: just blue colur
And when I pass series of LSM Dicom image, system get stuck and later viewer shows below image:
I don’t understand what I am doing wrong, same code work for CT without a problem but when I pass series of LSM Dicom image it gets stuck and doesn’t show the image at all.
I am running the above code on NVIDIA Gefore RTX 2060 6GB graphic card on a laptop.
Please provide me with some suggestions to overcome this problem.
Thank you!