【问题标题】:Wireframing from an image using matplotlib使用 matplotlib 从图像中绘制线框
【发布时间】:2020-06-20 18:19:01
【问题描述】:

我正在尝试使用带有 matplotlib 的线框将图像的 3D 表示为表面。

ig= mpimg.imread('testIMG.png');
X = np.linspace(0,len(ig[0]),len(ig[0])); #List of discrete x values
Y = np.linspace(0,len(ig[1]),len(ig[1])); #List of discrete y values

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

#Plot the wireframe
#I want to plot the image as f(x,y) and I can't understand why wireframe won't let me

ax.plot_wireframe(X, Y, ig[:,:,2], rstride=10, cstride=10)
plt.show()

imread 函数为我提供了一个 MxNx3 数组,其中包含 M 行、N 列以及矩阵中每个点的 RGB 值。我不明白如何使用线框正确绘制该数据。这些 z 值不是我所期望的(棋盘模式),而是在 0 和 1 之间交替的 y=x 线。

我需要在这里做什么?我想要一系列 3D 棋盘格图案的长方体。 Image of what I have currently

【问题讨论】:

    标签: python image matplotlib 3d


    【解决方案1】:

    你可以使用np.meshgrid(),所以:

    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    import numpy as np
    import mpl_toolkits.mplot3d
    
    ig = mpimg.imread('testIMG.png')
    x = np.linspace(0, ig.shape[1], ig.shape[1]) #List of discrete x values
    y = np.linspace(0, ig.shape[0], ig.shape[0]) #List of discrete y values
    
    X, Y = np.meshgrid(x, y)
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    
    #Plot the wireframe
    #I want to plot the image as f(x,y) and I can't understand why wireframe won't let me
    
    ax.plot_wireframe(X, Y, ig[:,:,2], rstride=10, cstride=10)
    
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-31
      • 1970-01-01
      • 1970-01-01
      • 2017-11-24
      • 2017-06-07
      • 1970-01-01
      • 2017-01-02
      • 2013-12-20
      相关资源
      最近更新 更多