Hello - I am trying to do a MIP on the DICOM images. Not sure what I am doing wrong any help would be appreciated. Here is my code. I am unable to set up the pipeline I believe to scroll through the stack with the MIP.
I am using a NIFTI image reader to read the volume.
PathDicom = “/Desktop/TempDICOM/0/0.nii”
reader = vtk.vtkNIFTIImageReader()
reader.SetFileName(PathDicom)
reader.Update()
I then get the centre of the volume which is required to set the plane
center = reader.GetOutput().GetCenter()
I do a histogram range that can be set to the image for viewing.
hist = vtk.vtkImageHistogramStatistics()
hist.SetInputConnection(reader.GetOutputPort())
hist.Update()
hist_range = hist.GetAutoRange()
I create a lookup table
lut = vtk.vtkLookupTable()
ctf = vtk.vtkColorTransferFunction()
ctf.SetColorSpaceToDiverging()
ctf.AddRGBPoint(0, 0, 0, 0)
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)
#now I set the lookup table
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()
I create a plane, with the centre as the origin
plane = vtk.vtkPlane()
plane.SetOrigin(center)
#use imagereslicemapper to create MIP
imageResliceMapper = vtk.vtkImageResliceMapper()
imageResliceMapper.SetInputConnection(reader.GetOutputPort())
imageResliceMapper.SetSlicePlane(plane)
imageResliceMapper.SetSlabThickness(3)
imageResliceMapper.SetSlabTypeToMin()
imageResliceMapper.SetSlabSampleFactor(1)
imageResliceMapper.ResampleToScreenPixelsOff()
#I am using VTKImageviewer2 for visualisation
imageViewer = vtk.vtkImageViewer2()
imageViewer.SetInputConnection(reader.GetOutputPort())
#set the imagereslicemapper to the imageviewer2
imageViewer.GetImageActor().SetMapper(imageResliceMapper)
#set the lookuptabla to the imageviewer2
imageViewer.GetWindowLevel().SetLookupTable(lut)
#set the slice to be viewed
imageViewer.SetSlice(60)
#initiate renderer and renwin
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
imageViewer.SetupInteractor(renderWindowInteractor)
imageViewer.Render()
imageViewer.GetRenderer().ResetCamera()
imageViewer.Render()
renderWindowInteractor.Start()