question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Volume from RGBA numpy array

See original GitHub issue

Hi,

I was wondering whether vtkplotter supports indicating the color for each pixel separately in a Volume.

This for example doesn’t work as it renders a red structure (should be blue):

from vtkplotter import show, Volume
import numpy as np

import matplotlib as mpl
from matplotlib import cm

norm = mpl.colors.Normalize(vmin=0, vmax=255)
scalarMap = cm.ScalarMappable(norm=norm, cmap='Blues')

im = np.random.randint(0,255,(10,11,12)).astype(np.uint8)
im_rgb = scalarMap.to_rgba(im.flatten()).reshape(im.shape+(4,))

vol = Volume(im_rgb,shape=im_rgb.shape[:3],mode=1)

show(vol)

Thanks a lot! Best, Marvin

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
m-albertcommented, Jul 1, 2020

Those are great suggestions! (Sorry that I forgot to answer earlier)

It’s great to see how vedo is becoming even more powerful and mature 😃. Thanks so much!

1reaction
marcomusycommented, Feb 21, 2020

PS: Consider also removing the nested loops with:

import vtk
from vtkplotter import Volume
import numpy as np

vol = Volume(None, shape=(10,11,12), mode=0)
vol.alpha(0.4).jittering(False)
vol.GetProperty().IndependentComponentsOff()
vol.GetProperty().SetInterpolationTypeToNearest()

vol.imagedata().AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 4)
arr = vol.getPointArray()
arr[:] = np.random.randint(0,255, (10*11*12,4)).astype(np.uint8)

vol.show()

and also save memory with vtk.VTK_UNSIGNED_CHAR

Read more comments on GitHub >

github_iconTop Results From Across the Web

Combine 3 separate numpy arrays to an RGB image in Python
I would use Image.fromarray() to take the array to image but it attains 'F' mode by default when Image.merge requires 'L' mode images...
Read more >
numpy.flip — NumPy v1.24 Manual
Reverse the order of elements in an array along the given axis. The shape of the array is preserved, but the elements are...
Read more >
Bug in custom opacity map for volume · Issue #1085 - GitHub
When I wanted to set the color map with a 4d numpy array of rgba values, there was an error because the object...
Read more >
How RGB and Grayscale Images Are Represented in NumPy ...
A single RGB image can be represented using a three-dimensional (3D) NumPy array or a tensor. Since there are three color channels in...
Read more >
cortex.dataset.VolumeRGB — pycortex 1.2.4 documentation
Each data channel is represented as a separate Volume object (these can either be supplied explicitly as Volume objects or implicitly as numpy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found