Hello - I am building an application where by I have the options to apply LUT as well as CT Presets.
I am using vtkimageviewer2 for rendering the slices and I am using a nii image reader.
Not sure if what I am doing is the right way to apply CT Presets along with Colour Palettes simultaneously.
PathDicom = “/Desktop/TempDICOM/0/0.nii”
reader = vtk.vtkNIFTIImageReader()
reader.SetFileName(PathDicom)
reader.Update()
get the histogram range to optimally view the images
hist = vtk.vtkImageHistogramStatistics()
hist.SetInputConnection(reader.GetOutputPort())
hist.Update()
hist_range = hist.GetAutoRange()
1500 and 300 - is bone window
windowlevel = vtk.vtkImageMapToWindowLevelColors()
windowlevel.SetInputConnection(self.reader.GetOutputPort())
windowlevel.SetWindow(1500)
windowlevel.SetLevel(300)
windowlevel.Update()
lut = vtk.vtkLookupTable()
ctf = vtk.vtkColorTransferFunction()
ctf.SetColorSpaceToDiverging()
ctf.AddRGBPoint(0, 0, 0, 0)
ctf.AddRGBPoint(0.06, 0, 0, 0.36)
ctf.AddRGBPoint(0.16, 0.29, 0, 0.75)
ctf.AddRGBPoint(0.22, 0.48, 0, 0.89)
ctf.AddRGBPoint(0.31, 0.68, 0, 0.6)
ctf.AddRGBPoint(0.37, 0.76, 0, 0.36)
ctf.AddRGBPoint(0.5, 0.94, 0.31, 0)
ctf.AddRGBPoint(0.56, 1, 0.45, 0)
ctf.AddRGBPoint(0.81, 1, 0.91, 0)
ctf.AddRGBPoint(0.88, 1, 1, 0.38)
ctf.AddRGBPoint(1, 1, 1, 1)
lut.SetNumberOfTableValues(256)
lut.Build()
for i in range(0, 256):
rgb = list(ctf.GetColor(float(i) / 256)) + [1]
lut.SetTableValue(i, rgb)
the LUT in the above line is having the colour gradient that I would like to apply on the image.
now I build this LUT
lut.SetTableRange(hist_range[0], hist_range[1])
lut.SetSaturationRange(0, 0)
lut.SetHueRange(0, 1)
lut.SetValueRange(0, 1)
lut.SetNumberOfColors(256)
lut.Build()
use vtkimageviewer2 render the image.
here I use the window level lookup set previously to bone window as the inout to the image viewer
the color looktable is also set to the image viewer.
imageViewer = vtk.vtkImageViewer2()
imageViewer.SetInputConnection(windowlevel.GetOutputPort())
#set the lookuptable
imageViewer.GetWindowLevel().SetLookupTable(lut)
#render the image
imageViewer.SetSlice(60)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
imageViewer.SetupInteractor(renderWindowInteractor)
imageViewer.Render()
imageViewer.GetRenderer().ResetCamera()
imageViewer.Render()
renderWindowInteractor.Start()
What I have done above is it the right way of applying CT Presets and Colour LUT simultaneously?
Thanks,
Aravind