Python图 - 堆叠图像切片 [英] Python plot - stacked image slices
问题描述
我有一系列基本的2D图像(现在简称为3),它们彼此相关,类似于电影中的帧:
I have a series of basic 2D images (3 for simplicity for now) and these are related to each other, analogous to frames from a movie:
在python中我如何将这些切片堆叠在一起,如image1-> image2-> image-3?我正在使用pylab来显示这些图像。理想情况下,堆叠框架的等距视图会很好,或者是允许我在代码/渲染图像内旋转视图的工具。
Within python how may I stack these slices on top of each other, as in image1->image2->image-3? I'm using pylab to display these images. Ideally an isometric view of the stacked frames would be good or a tool allowing me to rotate the view within code/in rendered image.
任何帮助表示赞赏。显示的代码和图片:
Any assistance appreciated. Code and images shown:
from PIL import Image
import pylab
fileName = "image1.png"
im = Image.open(fileName)
pylab.axis('off')
pylab.imshow(im)
pylab.show()
推荐答案
你不能用imshow做到这一点,但你可以用 contourf ,如果这对你有用。这有点像kludge:
You can't do this with imshow, but you can with contourf, if that will work for you. It's a bit of a kludge though:
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
x = np.linspace(0, 1, 100)
X, Y = np.meshgrid(x, x)
Z = np.sin(X)*np.sin(Y)
levels = np.linspace(-1, 1, 40)
ax.contourf(X, Y, .1*np.sin(3*X)*np.sin(5*Y), zdir='z', levels=.1*levels)
ax.contourf(X, Y, 3+.1*np.sin(5*X)*np.sin(8*Y), zdir='z', levels=3+.1*levels)
ax.contourf(X, Y, 7+.1*np.sin(7*X)*np.sin(3*Y), zdir='z', levels=7+.1*levels)
ax.legend()
ax.set_xlim3d(0, 1)
ax.set_ylim3d(0, 1)
ax.set_zlim3d(0, 10)
plt.show()
文档在3D中实现的是这里。
The docs of what's implemented in 3D are here.
正如ali_m建议的那样,如果这对您不起作用,如果你可以想象它可以用VTk / MayaVi做到。
As ali_m suggested, if this won't work for you, if you can imagine it you can do it with VTk/MayaVi.
这篇关于Python图 - 堆叠图像切片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!