Here is my horizontal gradient results.The left one is opencv result and the other one is matlab result
I am trying to do horizontal and vertical gradient which H =[1,-1] and V=[1;-1]
Mat H_gradient,G_Filter1,kernel,V_gradient;
Mat kernelH(1, 2, CV_32F);
kernelH.at<float>(0,0) = 1.0f;
kernelH.at<float>(0,1) = -1.0f;
Mat kernelV(2, 1, CV_32F);
kernelV.at<float>(0,0) = 1.0f;
kernelV.at<float>(1,0) = -1.0f;
cvtColor( image, image, CV_RGB2GRAY );
filter2D( image, H_gradient, -1 ,kernelH , Point( -1, -1 ), 0, BORDER_DEFAULT );
filter2D( image, V_gradient, -1 ,kernelV , Point( -1, -1 ), 0, BORDER_DEFAULT );
But still not match with my matlab code results. I dont know why?
My matlab code for gradients
image=double(image);
% horizontal and vertical gradient
H=[1 -1];
V=[1;-1];
H_Gradient=conv2(image,H,'same');
V_Gradient=conv2(image,V,'same');