Sobel filter kernel of large size

后端 未结 9 800
渐次进展
渐次进展 2020-12-02 08:38

I am using a sobel filter of size 3x3 to calculate the image derivative. Looking at some articles on the internet, it seems that kernels for sobel filter for size 5x5 and 7x

9条回答
  •  甜味超标
    2020-12-02 09:27

    Matlab implementation of Daniel's answer:

    kernel_width = 9;
    
    halfway = floor(kernel_width/2);
    step = -halfway : halfway;
    
    i_matrix = repmat(step,[kernel_width 1]);
    j_matrix = i_matrix';
    
    gx = i_matrix ./ ( i_matrix.*i_matrix + j_matrix.*j_matrix );
    gx(halfway+1,halfway+1) = 0; % deals with NaN in middle
    
    gy = gx';
    

提交回复
热议问题