Implementing Gaussian Blur - How to calculate convolution matrix (kernel)

后端 未结 7 2050
予麋鹿
予麋鹿 2020-12-22 21:14

My question is very close to this question: How do I gaussian blur an image without using any in-built gaussian functions?

The answer to this question is very good,

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-22 21:58

     function kernel = gauss_kernel(m, n, sigma)
     % Generating Gauss Kernel
    
     x = -(m-1)/2 : (m-1)/2;
     y = -(n-1)/2 : (n-1)/2;
    
     for i = 1:m
         for j = 1:n
             xx(i,j) = x(i);
             yy(i,j) = y(j);
         end
     end
    
     kernel = exp(-(xx.*xx + yy.*yy)/(2*sigma*sigma));
    
     % Normalize the kernel
     kernel  = kernel/sum(kernel(:));
    
     % Corresponding function in MATLAB
     % fspecial('gaussian', [m n], sigma)
    

提交回复
热议问题