我正在使用mayavi.mlab
在python中绘制通过卷的切割平面。
始终对渲染进行插值。有没有办法在没有插值的情况下绘制这些平面,以便像素/体素可见?
显示通过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()
输出
答案 0 :(得分:2)
我是mayavi的非常随意的用户,所以绝不是专家,但我确实设法在没有升级的情况下一起破解。为此,我使用image_plane_widget
代替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.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()
仅仅texture_interpolate = "off"
不起作用,如vtk docs中所述:
在设置vtkImageData输入之前设置。默认为开。
http://www.vtk.org/doc/nightly/html/classvtkImagePlaneWidget.html
答案 1 :(得分:1)
我能找到这个问题的最佳解决方法是使用scipy插值来放大音量而不插值。
from scipy.ndimage.interpolation import zoom
img3d2 = zoom(img3d, 4, order=0)
现在可以看到体素大小