Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot volume planes in python mayavi with no voxel interpolation

I'm using mayavi.mlab to plot cut planes through a volume in python.

The rendering is always interpolated. Is there a way to plot these planes without interpolation so that the pixels / voxels are visible?

Example code showing cut planes through a 20x20x20 voxel volume.

"""
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()

Output

enter image description here

like image 423
benj Avatar asked Apr 25 '26 08:04

benj


1 Answers

The best workaround that I could find to this problem was to use scipy interpolation to enlarge the volume without interpolation.

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

enter image description here

The voxel size is now visible

like image 135
benj Avatar answered Apr 26 '26 20:04

benj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!