Hi everyone,
I’m currently working on MIPs for the 3 anatomical planes but I ran into some issues with sagittal and frontal.
For those two I only get a completely black image as the output.
Below is the function to generate the MIP. (There might be a lot of bad style)
_input_connection is the outputPort from a vtkImageBlend. The blend currently only got one input connection from a vtkNIFTIImageReader.
If I put it directly into a vtkImageViewer2 and slice the image in there it works fine but for the MIP I need the vtkImageResliceMapper.
def __render_MIP(_input_connection : vtk.vtkAlgorithmOutput, _plane : int, _render_window : vtk.vtkRenderWindow, _renderer : vtk.vtkRenderer, _position : float):
dummy_algorithm = vtk.vtkImageWriter() #can basically use any vtkImageAlgorithm
dummy_algorithm.SetInputConnection(_input_connection)
image = dummy_algorithm.GetInput()
center = image.GetCenter()
hist = vtk.vtkImageHistogramStatistics()
hist.SetInputConnection(_input_connection)
hist.Update()
hist_range = hist.GetAutoRange()
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, 245):
rgb = list(ctf.GetColor(float(i) / 256)) + [1]
lut.SetTableValue(i, rgb)
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()
plane = vtk.vtkPlane()
plane.SetOrigin(center)
if _plane == vars.VIEW_SAGITTAL():
plane.SetNormal(1, 0, 0)
elif _plane == vars.VIEW_FRONTAL():
plane.SetNormal(0, 1, 0)
else:
plane.SetNormal(0, 0, 1)
image_reslice_mapper = vtk.vtkImageResliceMapper()
image_reslice_mapper.SetInputConnection(_input_connection)
image_reslice_mapper.SetSlicePlane(plane)
image_reslice_mapper.SetSlabThickness(3)
image_reslice_mapper.SetSlabTypeToMin()
image_reslice_mapper.SetSlabSampleFactor(1)
image_reslice_mapper.ResampleToScreenPixelsOff()
viewer = vtk.vtkImageViewer2()
viewer.SetInputConnection(_input_connection)
viewer.GetImageActor().SetMapper(image_reslice_mapper)
viewer.GetWindowLevel().SetLookupTable(lut)
max_slice = viewer.GetSliceMax()
viewer.SetSlice(int(max_slice * _position))
viewer.SetRenderWindow(_render_window)
viewer.SetRenderer(_renderer)
_renderer.ResetCamera()
return viewer, None
Would be fantastic if somebody could help me out here.