%% Implement the general filter equation (correlation)   ********************************************
    function mat = Correlation_kernel(Img, k)
        [m,n] = size(k);
        Rm = (m-1)/2;
        kCenterM = ceil(Rm+1);
        
        Rn = (n-1)/2;
        kCenterN = ceil(Rn+1);
        
        %Pad Img
        [m,n] = size(Img);
        ImgZ = zeros(m+2*Rm,n+2*Rn); ImgZ(1+Rm:m+Rm,1+Rn:n+Rn) = Img;
        
        [m,n] = size(ImgZ);
        matCorrelation = zeros(m,n);
        
        for u = 1+Rm:m-Rm
            for v = 1+Rn:n-Rn
                tmp = 0;
                tmp2 = 0;
                for i = -Rm:Rm
                    for j = -Rn:Rn
                        tmp = tmp + ImgZ(u+i,v+j) * k(kCenterM + i,kCenterN + j);
                        tmp2 = tmp2 + ImgZ(u-i,v-j) * k(kCenterM + i,kCenterN + j);
                    end
                end
                matCorrelation(u,v) = tmp;
            end
        end
        [m,n] = size(Img);
        mat = matCorrelation(1+Rm:m+Rm,1+Rn:n+Rn);

    end
