# Blank image with vtkImageMapToColors, works in vtk8

**URL:** https://discourse.vtk.org/t/blank-image-with-vtkimagemaptocolors-works-in-vtk8/4374
**Category:** Support
**Created:** [October 7, 2020, 3:35pm UTC](https://discourse.vtk.org/t/blank-image-with-vtkimagemaptocolors-works-in-vtk8/4374 "2020-10-07T15:35:08Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Nil](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nil/32/2428_2.png) [@Nil](https://discourse.vtk.org/u/Nil)
#### Post date: [October 7, 2020, 3:35pm UTC](https://discourse.vtk.org/t/blank-image-with-vtkimagemaptocolors-works-in-vtk8/4374/1 "2020-10-07T15:35:08Z")

</div>

This code, based on the [ImageMapToColors example](https://vtk.org/Wiki/VTK/Examples/Cxx/Images/ImageMapToColors), does what I want in vtk8, but it produces a blank image on vtk9.

```
width = 15
height = 15
data = np.arange(width * height, dtype='float32').reshape((width, height))

data_importer = vtk.vtkImageImport()
data_str = data.tostring()
data_importer.SetDataSpacing(1.0, 1.0, 1.0)
data_importer.SetDataOrigin(0.0, 0.0, 0.0)
data_importer.SetWholeExtent(0, width - 1, 0, height - 1, 0, 0)
data_importer.SetDataExtentToWholeExtent()
data_importer.SetDataScalarTypeToFloat()
data_importer.SetNumberOfScalarComponents(1)
data_importer.CopyImportVoidPointer(data_str, len(data_str))
data_importer.Update()

lut = vtk.vtkLookupTable()
lut.SetNumberOfTableValues(256)
lut.SetRange(0.0, 255.0)
lut.Build()

color = vtk.vtkImageMapToColors()
color.SetLookupTable(lut)
color.PassAlphaToOutputOn()
color.SetInputConnection(data_importer.GetOutputPort())

actor = vtk.vtkImageActor()
actor.SetInterpolate(False)
actor.GetMapper().SetInputConnection(color.GetOutputPort())

renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderer.ResetCamera()

render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(render_window)
iren.Initialize()
iren.Start()

```

The image is ok in vtk9 only when I remove the vtkLookupTable and vtkImageMapToColors parts, but I need to use a LUT for the application I’m trying to code. What do I need to modify to have a working image in vtk9?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 7, 2020, 5:07pm UTC](https://discourse.vtk.org/t/blank-image-with-vtkimagemaptocolors-works-in-vtk8/4374/2 "2020-10-07T17:07:56Z")

</div>

Thanks for including the code. However, it works fine for me with VTK 9. The image is red at the bottom left, progressing to blue at the top right.

Can you provide more information about your system and about the VTK package that you are using? I ran your test on linux (ubuntu 20.04), with a VTK 9 that I built from source against the system libraries (i.e. not a pip or conda package).

---

<div class="post-metadata">

### Author: ![Nil](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nil/32/2428_2.png) [@Nil](https://discourse.vtk.org/u/Nil)
#### Post date: [October 7, 2020, 6:08pm UTC](https://discourse.vtk.org/t/blank-image-with-vtkimagemaptocolors-works-in-vtk8/4374/3 "2020-10-07T18:08:53Z")

</div>

My system is not super clean! I ran both versions in VMware, with WMware tools installed, vtk installed with pip.

1. Mint 19.3 Python 3.6 vtk8 ✓
2. Mint 19.3 Python 3.6 vtk9 ❌
3. Mint 20.0 Python 3.8 vtk9 ❌

However, I asked my colleagues who have a real linux installation (not a vm) to test it for me.

1. Mint 19.2 Python 3.7 vtk9 (pip) ✓
2. Archlinux Python 3.8 vtk9 (apt) ✓

It looks like there’s something wrong with my VM. Are there some known problems to using a vm with vtk9? I’ve been using this code in a vm for years without any troubles so I’m quite surprised!

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 7, 2020, 7:58pm UTC](https://discourse.vtk.org/t/blank-image-with-vtkimagemaptocolors-works-in-vtk8/4374/4 "2020-10-07T19:58:11Z")

</div>

Do you know which OpenGL backend was used to build your vtk8 package? It might be incompatible with vmware’s GL.

If it uses the old backend, then this will succeed:

```
import vtk.vtkRenderingOpenGL

```

For the new backend, the module’s name is vtkRenderingOpenGL2.

---

<div class="post-metadata">

### Author: ![Nil](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nil/32/2428_2.png) [@Nil](https://discourse.vtk.org/u/Nil)
#### Post date: [October 8, 2020, 3:58pm UTC](https://discourse.vtk.org/t/blank-image-with-vtkimagemaptocolors-works-in-vtk8/4374/5 "2020-10-08T15:58:44Z")

</div>

`ModuleNotFoundError: No module named 'vtk.vtkRenderingOpenGL'`  
But `vtk.vtkRenderingOpenGL2` can be imported without trouble (still got a blank image)

I tried building vtk 9.0.1 + Python wrapping myself, everything went well, I deleted the pip version, I added `~/VTK-9.0.1/_build/lib/python3.8/site-packages` to my PYTHONPATH and run the program … I got the same blank image again ☹

Unless you have other ideas, I’ll simply code my project on a non-vm environment.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 8, 2020, 4:21pm UTC](https://discourse.vtk.org/t/blank-image-with-vtkimagemaptocolors-works-in-vtk8/4374/6 "2020-10-08T16:21:45Z")

</div>

Well, at least now we know that the OpenGL2 backend isn’t completely incompatible with vmware. Rather, the issue occurred within the OpenGL2 backend sometime between VTK 8 and VTK 9. Unfortunately it would take some detective work to identify exactly what change caused the problem.

Hopefully someone out there who has experience with VTK9 + vmware can provide some insight?
