Python 3d image overlay

I have a 3D plot of lines created by matplotlib. I want to overlay the image on a specific fragment of xy (or yz, xz). How to do it with python? Thanks.

I have a simple three-dimensional code:

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

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

 ax.overlay(Im, slice='xy', sliceNo=10) 
+7
source share
1 answer

I made a three-dimensional inscription of the plot layer on top of the background image:

3d surface plot on top of background image

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

Alternatively, if you just want to display the image in three-dimensional 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, step values ​​can be reduced to 1 for better image quality, but then drawing will take loooong =)

The resulting image from the code above:

enter image description here

+20
source

All Articles