Surface Curvature Matlab equivalent in Python

后端 未结 6 1436
野的像风
野的像风 2021-01-05 18:21

I was trying to calculate the curvature of a surface given by array of points (x,y,z). Initially I was trying to fit a polynomial equation z=a + bx + cx^2 + dy + exy + fy^2)

6条回答
  •  [愿得一人]
    2021-01-05 18:57

    In case others stumble across this question, for completeness I offer the following code, inspired by heltonbiker.

    Here is some python code to calculate Gaussian curvature as described by equation (3) in "Computation of Surface Curvature from Range Images Using Geometrically Intrinsic Weights"*, T. Kurita and P. Boulanger, 1992.

    import numpy as np
    
    def gaussian_curvature(Z):
        Zy, Zx = np.gradient(Z)                                                     
        Zxy, Zxx = np.gradient(Zx)                                                  
        Zyy, _ = np.gradient(Zy)                                                    
        K = (Zxx * Zyy - (Zxy ** 2)) /  (1 + (Zx ** 2) + (Zy **2)) ** 2             
        return K
    

    Note:

    1. heltonbiker's method is essentially equation (4) from the paper
    2. heltonbiker's method is also the same on "Surfaces in 3D space, Mean Curvature" on Wikipedia: http://en.wikipedia.org/wiki/Mean_curvature)
    3. If you need both K and H then include the calculation of "K" (Gaussian curvature) in heltonbiker code and return K and H. Saves a little processing time.
    4. I assume the surface is defined as a function of two coordinates, e.g. z = Z(x, y). In my case Z is a range image.

提交回复
热议问题