Search code examples
image-processingcomputer-visionedge-detectionsobel

Sobel filter kernel of large size


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 7x7 are also common, but I am not able to find their kernel values.

Could someone please let me know the kernel values for sobel filter of size 5x5 and 7x7? Also, if someone could share a method to generate the kernel values, that will be much useful.

Thanks in advance.


Solution

  • UPDATE 23-Apr-2018: it seems that the kernels defined in the link below are not true Sobel kernels (for 5x5 and above) - they may do a reasonable job of edge detection, but they should not be called Sobel kernels. See Daniel’s answer for a more accurate and comprehensive summary. (I will leave this answer here as (a) it is linked to from various places and (b) accepted answers can not easily be deleted.)

    Google seems to turn up plenty of results, e.g. http://rsbweb.nih.gov/nih-image/download/user-macros/slowsobel.macro suggests the following kernels for 3x3, 5x5, 7x7 and 9x9:

    3x3:

    1   0   -1
    2   0   -2
    1   0   -1
    

    5x5:

    2   1   0   -1  -2
    3   2   0   -2  -3
    4   3   0   -3  -4
    3   2   0   -2  -3
    2   1   0   -1  -2
    

    7x7:

    3   2   1   0   -1  -2  -3
    4   3   2   0   -2  -3  -4
    5   4   3   0   -3  -4  -5
    6   5   4   0   -4  -5  -6
    5   4   3   0   -3  -4  -5
    4   3   2   0   -2  -3  -4
    3   2   1   0   -1  -2  -3
    

    9x9:

    4   3   2   1   0   -1  -2  -3  -4
    5   4   3   2   0   -2  -3  -4  -5
    6   5   4   3   0   -3  -4  -5  -6
    7   6   5   4   0   -4  -5  -6  -7
    8   7   6   5   0   -5  -6  -7  -8
    7   6   5   4   0   -4  -5  -6  -7
    6   5   4   3   0   -3  -4  -5  -6
    5   4   3   2   0   -2  -3  -4  -5
    4   3   2   1   0   -1  -2  -3  -4