如何在 Python 中创建基于像素强度的 3D 绘图?

问题描述 投票:0回答:1

我有一个 TIF 图像,并根据其像素强度,我的目标是生成 3D 图。我遇到了一个示例图像,它代表了我想要实现的可视化类型:

3D reconstruction sample

请注意,上图只是一个示例。我的目标是制作一个类似情节的情节。我们将不胜感激您的支持。

python image-processing plot 3d visualization
1个回答
0
投票

免责声明

我建议不要这样的情节。它可能看起来很酷,但与仅在底部绘制热图相比,它没有提供任何附加信息,实际上它提供了“更少”的信息,因为热图的一部分被隐藏了。示例中的 3d 图根本没有提供任何信息。 如何使用

matplotlib

 实现此图
import matplotlib.pyplot as plt import numpy as np from PIL import Image def create_example_file(filename: str) -> None: """Create an example image""" X = np.arange(-2.5 * np.pi, 3.5 * np.pi, 0.25) Y = np.arange(-2.5 * np.pi, 3.5 * np.pi, 0.25) xx, yy = np.meshgrid(X, Y) zz = ((np.sin(xx) + np.sin(yy)) + 2) * (255 / 4) Image.fromarray(zz.astype(np.uint8)).save(filename) filename = 'image.tiff' create_example_file(filename) img = Image.open(filename) X = np.arange(img.size[0]) Y = np.arange(img.size[1]) xx, yy = np.meshgrid(X, Y) zz = np.array(img) fig = plt.figure() ax = fig.add_subplot(projection='3d') ax.plot_surface(xx, yy, zz, cmap='viridis') C = ax.contourf(xx, yy, zz, z_dir='z', offset=-300, cmap='viridis') ax.set_zlim(-300, 255) ax.set_xlabel('x-Axis') ax.set_ylabel('y-Axis') ax.set_zlabel('z-Axis') fig.colorbar(C, ax=ax, fraction=0.02, pad=0.1) fig.tight_layout()

© www.soinside.com 2019 - 2024. All rights reserved.