[vtkusers] Color a contour from a Niftii image

Renzo rphellan2210 at gmail.com
Tue Oct 9 22:41:32 EDT 2018


Hello,

I am trying to generate a visualization of a contour of a Niftii file, but
with colors interpolated from that same image, not a monochrome
representation. The resulting image shows the color variation, but it does
not use the colors I set in my lookup table. Do you know why this could be
happening? I wonder if it is because of the interpolation affecting not only
hue, but also saturation and value parameters.

My code is below.

NiftiReader = vtk.vtkNIFTIImageReader()  

ren = vtk.vtkRenderer()
ren.SetBackground(0, 0, 0)
renWin = vtk.vtkRenderWindow()
renWin.SetSize(800, 600)
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())

surface = vtk.vtkContourFilter()
surface.SetInputConnection(NiftiReader.GetOutputPort())
surface.SetValue(0,300)

#Colors
lut = vtk.vtkLookupTable()
lut.SetNumberOfColors(256)
lut.SetTableRange(400, 905)
lut.SetHueRange(0.0, 0.75)
lut.SetSaturationRange(1.0, 1.0)
lut.SetValueRange(1.0, 1.0)
lut.Build()

#Map to colors
mapToC = vtk.vtkImageMapToColors()
mapToC.PassAlphaToOutputOn()
mapToC.SetLookupTable(lut)
mapToC.SetInputConnection(NiftiReader.GetOutputPort()) 
#mapToC.SetOutputFormatToLuminance()
mapToC.Update()

#Probe
probe = vtk.vtkProbeFilter()
probe.SetInputConnection(surface.GetOutputPort())
probe.SetSourceConnection(mapToC.GetOutputPort())
probe.Update()

# Create a mapper and an actor for the extracted surface
smapper = vtk.vtkPolyDataMapper()
smapper.SetInputConnection(probe.GetOutputPort())
#smapper.ScalarVisibilityOn()
#smapper.SetLookupTable(lut)
#smapper.SetScalarRange(400, 905)
#smapper.SetScalarModeToUseCellData() 

actor = vtk.vtkActor()
actor.SetMapper(smapper)
ren.AddActor(actor)

iren.Initialize()
renWin.Render()
iren.Start()



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list