【问题标题】:Elevation distortion on sphere-projected image in PythonPython中球体投影图像的高程失真
【发布时间】:2017-09-01 15:29:51
【问题描述】:

我正在尝试拍摄两张矩形图像,一张是可见的表面特征,一张表示高程,然后将它们映射到 3D 球体上。我知道如何使用Cartopy 将要素映射到球体上,并且我知道如何制作relief surface maps,但我找不到一种简单的方法将它们组合起来以在球形投影上具有夸张的高程。例如,here's it done in MATLAB

有人知道在 Python 中是否有一种简单的方法可以做到这一点?

【问题讨论】:

    标签: python matplotlib projection


    【解决方案1】:

    我的解决方案不能满足您的所有要求。但它可能是一个很好的开始。

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    import numpy as np
    from matplotlib.cbook import get_sample_data
    from matplotlib._png import read_png
    
    # Use world image with shape (360 rows, 720 columns) 
    pngfile = 'temperature_15-115.png'
    
    fn = get_sample_data(pngfile, asfileobj=False)
    img = read_png(fn)   # get array of color
    
    # Some needed functions / constant
    r = 5
    pi = np.pi
    cos = np.cos
    sin = np.sin
    sqrt = np.sqrt
    
    # Prep values to match the image shape (360 rows, 720 columns)
    phi, theta = np.mgrid[0:pi:360j, 0:2*pi:720j]
    
    # Parametric eq for a distorted globe (for demo purposes)
    x = r * sin(phi) * cos(theta)
    y = r * sin(phi) * sin(theta)
    z = r * cos(phi) + 0.5* sin(sqrt(x**2 + y**2)) * cos(2*theta)
    
    fig = plt.figure()
    fig.set_size_inches(9, 9)
    ax = fig.add_subplot(111, projection='3d', label='axes1')
    
    # Drape the image (img) on the globe's surface
    sp = ax.plot_surface(x, y, z, \
                    rstride=2, cstride=2, \
                    facecolors=img)
    
    ax.set_aspect(1)
    
    plt.show()
    

    生成的图像:

    【讨论】:

    • 我还没有机会尝试它,但它看起来正是我所需要的。谢谢!
    猜你喜欢
    • 2014-04-23
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    • 2017-06-14
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    相关资源
    最近更新 更多