1. 程式人生 > >使用opencv-python實現MATLAB的fspecial('Gaussian', [r, c], sigma)

使用opencv-python實現MATLAB的fspecial('Gaussian', [r, c], sigma)

reference_opencv實現高斯核
reference_MATLAB_fspecial函式說明

# MATLAB
H = fspecial('Gaussian', [r, c], sigma);
# opencv-python
# cv2.getGaussianKernel(r, sigma)返回一個shape為(r, 1)的np.ndarray, fspecial裡核的size的引數是先行後列, 因此:
H = np.multiply(cv2.getGaussianKernel(r, sigma), (cv2.getGaussianKernel(c, sigma)).T)  # H.shape == (r, c)