使用python的3​​D绘图影像合成 [英] Image overlay in 3d plot using python

查看:1530
本文介绍了使用python的3​​D绘图影像合成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得matplotlib产生线的3D图。我要叠加的图像在特定XY(或YZ,XZ)片。我该怎么做,使用蟒蛇?谢谢你。

我有一个简单的3D绘图code为:

 图= plt.figure(1),其中; BR>
AX = Axes3D(图)< BR>
ax.plot(六[:,0]中,f [:,1]中,f [:,2],颜色=R)
 

我也有一个像林(二维数组),所以我需要的东西,如:

  ax.overlay(IM,片='XY',sliceNo = 10)
 

解决方案

我做了一个三维表面图覆盖上一次的背景图像的顶部:

如果这类似于你想要什么,我可以尝试做一个工作的例子出来。

另外,如果你只是想显示在三维空间中的图像,你可以使用曲面图:

 从pylab进口*
从mpl_toolkits.mplot3d进口Axes3D
从matplotlib.cbook进口get_sample_data
从matplotlib._png进口read_png
FN = get_sample_data(lena.png,asfileobj =假)
IMG = read_png(FN)
的x,y = ogrid [0:img.shape [0],0:img.shape [1]]
AX = GCA(投影='3D')
ax.plot_surface(X,Y,10,rstride = 5,cstride = 5,facecolors =图片)
显示()
 

当然,步幅值可以降低到1更好的图像质量,但后来绘制将loooong =)

生成的图像从上面code:

I have a 3d plot of lines generated by matplotlib. I want to overlay an image at a specific xy (or yz, xz) slice. How do I do that using python? Thanks.

I have a simple 3d plot code as:

fig = plt.figure(1),<br>
ax = Axes3D(fig)<br>
ax.plot(f[:,0], f[:,1], f[:,2], color='r')

I also have an image "Im" (a 2d array), so I need something like:

ax.overlay(Im, slice='xy', sliceNo=10)

解决方案

I did a 3d surface plot overlay on top of a background image once:

If this is similar to what you want, I could try to make a working example out of it.

Alternatively, if you just want to display an image in 3d space, you can use a surface plot:

from pylab import *
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.cbook import get_sample_data
from matplotlib._png import read_png
fn = get_sample_data("lena.png", asfileobj=False)
img = read_png(fn)
x, y = ogrid[0:img.shape[0], 0:img.shape[1]]
ax = gca(projection='3d')
ax.plot_surface(x, y, 10, rstride=5, cstride=5, facecolors=img)
show()

Of course, the stride values can be decreased to 1 for better image quality, but then drawing will take loooong =)

Resulting image from above code:

这篇关于使用python的3​​D绘图影像合成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆