Sobel core template of opencv source code

The pad method of the opencv filter operator

Opencv filter operator, if ksize!=1, if no pad is added around the image, the size of the filtered image will become smaller. In order to keep the size of the filtered image unchanged, the opencv function will add pads around the image, as follows pad method, the default method is BORDER_REFLECT_101.

enum BorderTypes {
    BORDER_CONSTANT    = 0, //!< `iiiiii|abcdefgh|iiiiiii`  with some specified `i`
    BORDER_REPLICATE   = 1, //!< `aaaaaa|abcdefgh|hhhhhhh`
    BORDER_REFLECT     = 2, //!< `fedcba|abcdefgh|hgfedcb`
    BORDER_WRAP        = 3, //!< `cdefgh|abcdefgh|abcdefg`
    BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba`
    BORDER_TRANSPARENT = 5, //!< `uvwxyz|abcdefgh|ijklmno`

    BORDER_REFLECT101  = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
    BORDER_DEFAULT     = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
    BORDER_ISOLATED    = 16 //!< do not look outside of ROI
};

Sobel's Template Generation Function

The generation of Sobel's kernel template implemented by opencv is a separate function, and it can be observed what the specific kernel function is when different k_sizes are used.

void test_getSobelKernel()
{
    Mat kx,ky;
    int dx=1;
    int dy=0;
    int ksize=5;
    getDerivKernels(kx,ky,dx,dy,ksize,false, CV_32F);
    cout<<kx<<endl;
    cout<<ky<<endl;

}

当ksize=3,(dx,dy)=(1,0)

kx=[-1;  0;  1]

ky=[1;  2;  1]

当ksize=3,(dx,dy)=(0,1)

kx=[1;  2;  1]

ky=[-1;  0;  1]

当ksize=3,(dx,dy)=(1,1)

kx=[-1;  0;  1]

ky=[-1;  0;  1]

The calculation process of the Sobel function:
1. Calculate the kerel template value.

2, Call the sepFilter2D function to speed up the calculation.

 

Guess you like

Origin blog.csdn.net/u010420283/article/details/128461409