# vtk map scala to target color, but vtkLookupTable works not ok.

**URL:** <https://discourse.vtk.org/t/vtk-map-scala-to-target-color-but-vtklookuptable-works-not-ok/11225>\
**Category:** Development\
**Tags:** code, file-formats\
**Created:** [April 17, 2023, 6:53am UTC](https://discourse.vtk.org/t/vtk-map-scala-to-target-color-but-vtklookuptable-works-not-ok/11225 "2023-04-17T06:53:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LightSun](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lightsun/32/6904_2.png) [@LightSun](https://discourse.vtk.org/u/LightSun)\
**Post date:** [April 17, 2023, 6:53am UTC](https://discourse.vtk.org/t/vtk-map-scala-to-target-color-but-vtklookuptable-works-not-ok/11225/1 "2023-04-17T06:53:02Z")

</div>

Hello , I am new to VTK. I have a problem with display 3d image data.  
the color display is not my want.  
I have a nifti image data with only four scala values: 0 ,1, 2, 3.  
And I want 0 map to black, and 1 map to red, 2 map to green, 3 map to blue.  
Could anyone help me?

```auto
# nifti image data with only four scala values: 0 ,1, 2, 3.
# I want 0 map to black, and 1 map to red, 2 map to green, 3 map to blue. 
_file = "/xxx/work/IAS/debug_out/mvh_thy_nodule.nii" # u8 data, single channel 
reader = vtk.vtkNIFTIImageReader()
reader.SetFileName(_file)
reader.Update()
image_data = reader.GetOutput()

# Create a lookup table to map scalar values to colors
lookup_table = vtk.vtkLookupTable()
lookup_table.SetNumberOfTableValues(4)
lookup_table.SetTableValue(0, 0, 0, 0, 1.0)
lookup_table.SetTableValue(1, 1, 0, 0, 1.0)
lookup_table.SetTableValue(2, 0, 1, 0, 1.0)
lookup_table.SetTableValue(3, 0, 0, 1, 1.0)
lookup_table.Build()

# Create a contour filter to create a surface from the image data
contour_filter = vtk.vtkDiscreteMarchingCubes()
contour_filter.SetInputData(image_data)
contour_filter.Update()

# Create a mapper for the contour filter output
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(contour_filter.GetOutputPort())
mapper.SetLookupTable(lookup_table)
mapper.SetColorModeToMapScalars()
mapper.ScalarVisibilityOn()
mapper.SetScalarRange(0, 3)

# Create an actor for the surface and set the mapper
actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Create a renderer, add the actor to it, and set the background color
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderer.SetBackground(0.1, 0.2, 0.4)

# Create a render window and add the renderer to it
render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)

# Create an interactor style and set it on the render window interactor
interactor_style = vtk.vtkInteractorStyleTrackballCamera()
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(render_window)
interactor.SetInteractorStyle(interactor_style)

# Render the scene and start the interactor
render_window.Render()
interactor.Start()

```

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)\
**Post date:** [April 24, 2023, 3:41am UTC](https://discourse.vtk.org/t/vtk-map-scala-to-target-color-but-vtklookuptable-works-not-ok/11225/2 "2023-04-24T03:41:46Z")

</div>

@cory.quammen ?
