Volume from RGBA numpy array
See original GitHub issueHi,
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:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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!
PS: Consider also removing the nested loops with:
and also save memory with
vtk.VTK_UNSIGNED_CHAR