在 python mayavi 中绘制体积平面,没有体素插值
Plot volume planes in python mayavi with no voxel interpolation
我正在使用 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()
输出
我能找到的解决此问题的最佳解决方法是使用 scipy 插值来放大音量而不用插值。
from scipy.ndimage.interpolation import zoom
img3d2 = zoom(img3d, 4, order=0)
体素大小现在可见
我是一个非常随意的 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 文档中所述:
Set before setting the vtkImageData input. Default is On.
http://www.vtk.org/doc/nightly/html/classvtkImagePlaneWidget.html
我正在使用 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()
输出
我能找到的解决此问题的最佳解决方法是使用 scipy 插值来放大音量而不用插值。
from scipy.ndimage.interpolation import zoom
img3d2 = zoom(img3d, 4, order=0)
体素大小现在可见
我是一个非常随意的 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 文档中所述:
Set before setting the vtkImageData input. Default is On.
http://www.vtk.org/doc/nightly/html/classvtkImagePlaneWidget.html