How to gauss-filter (blur) a floating point numpy array

后端 未结 3 649
小鲜肉
小鲜肉 2021-02-01 04:39

I have got a numpy array a of type float64. How can I blur this data with a Gauss filter?

I have tried

from PIL import Image,          


        
3条回答
  •  遇见更好的自我
    2021-02-01 05:06

    Purely numpy solution using convolve and the separability of the Gaussian filter into two separate filter steps (which makes it relatively fast):

    kernel = np.array([1.0,2.0,1.0]) # Here you would insert your actual kernel of any size
    a = np.apply_along_axis(lambda x: np.convolve(x, kernel, mode='same'), 0, a)
    a= np.apply_along_axis(lambda x: np.convolve(x, kernel, mode='same'), 1, a)
    

提交回复
热议问题