简体   繁体   English

使用 matplotlib 或 PIL 将 3d numpy 数组绘制为 3d 图像

[英]plot 3d numpy array as a 3d image using matplotlib or PIL

After looking at various related answers, I could not figure out a straight way.在查看了各种相关的答案后,我想不出一个直接的方法。

I have a 3-d numpy array of shape (390, 280, 160) .我有一个形状为(390, 280, 160)的 3-d numpy 数组。 I want to visualize this as an image.我想将其形象化为图像。 What could be the simplest way to do it?什么是最简单的方法?

Here is a minimal example of volumetric plot using mayavi.这是使用 mayavi 的体积图的最小示例。
You can find more examples of 3d data visualization here您可以在此处找到更多 3d 数据可视化示例

from mayavi import mlab
import numpy as np

s = np.random.rand(20, 20, 20)
volume = mlab.pipeline.volume(mlab.pipeline.scalar_field(s), vmin=0, vmax=0.8)

mlab.draw()
mlab.savefig('output.png')

在此处输入图片说明

From mayavi docs来自 mayavi 文档

For such a visualization, tweaking the opacity transfer function is critical to achieve a good effect.对于这样的可视化,调整不透明度传递函数对于实现良好效果至关重要。 Typically, it can be useful to limit the lower and upper values to the 20 and 80 percentiles of the data, in order to have a reasonable fraction of the volume transparent.通常,将下限值和上限值限制在数据的 20 和 80 个百分位数内可能很有用,以便使体积的合理部分透明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM