2015-03-03 1 views
2

J'utilise mayavi.mlab pour tracer des plans de coupe à travers un volume en python.Plot volume plans dans python mayavi sans interpolation voxel

Le rendu est toujours interpolé. Existe-t-il un moyen de tracer ces plans sans interpolation afin que les pixels/voxels soient visibles?

Exemple de code montrant des plans de coupe à travers un volume de voxel 20x20x20.

""" 
Testing scalar_cut_plane 
""" 
import numpy as np 
import mayavi.mlab as mlab 

# creating volume that increases in value 
img3d = np.arange(20) 
img3d = np.expand_dims(img3d, axis=1) 
img3d = np.expand_dims(img3d, axis=2) 
img3d = np.tile(img3d, (1, 20, 20)) 

fig = mlab.figure() 
src = mlab.pipeline.scalar_field(img3d) 

# Plotting two cut planes 
cp2 = mlab.pipeline.scalar_cut_plane(src, plane_orientation='y_axes') 
cp2.implicit_plane.widget.enabled = False 
cp3 = mlab.pipeline.scalar_cut_plane(src, plane_orientation='z_axes') 
cp3.implicit_plane.widget.enabled = False 
mlab.view(azimuth=50, elevation=None) 
mlab.outline() 
mlab.show() 

Sortie

enter image description here

Répondre

1

La meilleure solution que je pouvais trouver à ce problème est d'utiliser l'interpolation scipy pour agrandir le volume sans interpolation.

from scipy.ndimage.interpolation import zoom 
img3d2 = zoom(img3d, 4, order=0) 

enter image description here

La taille de voxel est maintenant visible

1

Je suis un utilisateur très décontracté de mayavi, donc absolument pas un expert, mais j'ai réussi à pirater quelque chose ensemble sans upscaling. Pour cela j'ai utilisé image_plane_widget au lieu de scalar_cut_plane, pas tout à fait sûr de la différence.

import numpy as np 
import mayavi.mlab as mlab 

# creating volume that increases in value 
img3d = np.arange(20) 
img3d = np.expand_dims(img3d, axis=1) 
img3d = np.expand_dims(img3d, axis=2) 
img3d = np.tile(img3d, (1, 20, 20)) 

fig = mlab.figure() 
src = mlab.pipeline.scalar_field(img3d) 

# Plotting two cut planes 
cp2 = mlab.pipeline.image_plane_widget(src, plane_orientation='y_axes') 
cp3 = mlab.pipeline.image_plane_widget(src, plane_orientation='z_axes') 

for p in [cp2, cp3]: 
    p.ipw.texture_interpolate = "off" 
    p.ipw.set_input_data(p.ipw._get_input()) 

mlab.view(azimuth=50, elevation=None) 
mlab.outline() 
mlab.show() 

mayavi image_plane_widget texture interpolation

Un simple texture_interpolate = "off" ne fonctionne pas, comme mentionné dans les VTK docs:

Set avant de l'entrée vtkImageData. La valeur par défaut est On.

http://www.vtk.org/doc/nightly/html/classvtkImagePlaneWidget.html