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.

Coloring isosurfaces and voxels in numpy array

See original GitHub issue

Hey

i have been using vtkplotter and its really awesome how you can do so much with so little code. I have been using it visualize volumetric data of the mouse brain and i have some doubts. My input data is a list of brain structures with associated voxels. I create a volume object and then use isosurfaces to extract the mesh. Now i want to color the different structures whose voxels i know according to different colors in the isosurfaces as well (if i can get a mesh i can smooth it and make it look prettier)

Once i have this i have a list of gene expression values for the voxels. I want to then color the voxels with the intensity of the gene expression values. We can think of this as some list of values for each voxel in a structure and then i want the color to have a gradient that follows these provided values.

I havent been able to do the visualization of the voxel values according to gene expression values. I feel that if i change the labels according to the gene expression values then i can see the colors but i dont know if perceptually it will look good. Also it would be nice to figure out how to set the colors of the different voxels in isosurface.

Thanks once again for this amazing tool

    labels = list(label_dic.values())
    ts = [i for i in range(0, np.amax(labels), 5)]
    vol = Volume(rg, c=colors_)
    isos = vol.isosurface(threshold=ts)
    isos = isos.opacity(alpha = 0.3)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
anorak94commented, May 19, 2020

sorry the doc doesnt do anything but the name works now

1reaction
marcomusycommented, May 18, 2020

Hi, I think I found a better solution that will not need you to split regions. Do: pip install -U git+https://github.com/marcomusy/vtkplotter.git Then:

"""A Volume can have multiple
scalars associated to each voxel"""
from vtkplotter import *
import numpy as np
import pickle

with open('rg_tmp.pkl','rb') as f: arr = pickle.load(f)

vol = Volume(arr).printInfo()
nx, ny, nz = vol.dimensions()
r0,r1 = vol.scalarRange()
vol.addScalarBar3D(title='original voxel scalars')

# create a set of scalars and add it to the Volume
sc1 = np.linspace(r0,r1, num=nx*ny*nz)#.astype(np.uint8)
vol.addPointArray(sc1, "myscalars1")

# create another set of scalars and add it to the Volume
sc2 = np.random.randint(r0,r1, nx*ny*nz)
vol.addPointArray(sc2, "myscalars2")

# make input_scalars the active array (can set 0, to pick the first):
printc('Arrays in Volume are:\n', vol.getArrayNames(), invert=1)
vol.getPointArray('input_scalars')

# Build the isosurface of the active scalars,
# but use testscals1 to colorize this isosurface, and then smooth it
iso1 = vol.isosurface().pointColors('myscalars1').smoothWSinc().lw(0.1)
iso1.addScalarBar3D(title='myscalars1')

iso2 = vol.isosurface().pointColors('myscalars2', cmap='viridis')
iso2.addScalarBar3D(title='myscalars2')

show([(vol, __doc__),
      (iso1,"Colorize isosurface using\nmyscalars1"),
      (iso2,"Colorize isosurface using\nmyscalars2"),
     ], N=3, axes=1)

an

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coloring isosurfaces and voxels in numpy array #147 - GitHub
I want to pass the value of these variables and color the voxels or the mesh i get from the voxels with a...
Read more >
Geosoft Voxel - Jupyter Notebooks Gallery
A Vox instance can be displayed withion a 3D view either as a solid with each cell assigned a color, or as a...
Read more >
vtk - How do you voxelize an isosurface of a 3D scalar field in ...
I was able to voxelize a surface but cannot retrieve their data. Questions. Where is the voxel data (coordinates etc.) stored in the...
Read more >
Coloring surfaces in slicer - Support
My script returns a 3d array that assigns a thickness to each point on a surface ... You can get model point positions...
Read more >
Convert a 3D NumPy array of voxels to an STL file
Given a 3D boolean array representing voxels, how can it be converted to a 3D-printer-ready file? The end-goal I would like to achieve...
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