title: Manual implementation of OpenCV Sobel function
body: <p><img src="https://i.stack.imgur.com/Nj9fM.png" alt="My image"></p>
  
  <p>If I have an image and call the OpenCV Sobel function with </p>
  
  <pre><code>Sobel(Img,gradX,CV_16S,1,0,3);
  convertScaleAbs(gradX,absGradX);
  imshow("Gradient Image",absGradX);
  </code></pre>
  
  <p>I get a nice gradient image</p>
  
  <p>I would like to use filter2D with a custom kernel to calculate my x gradient. My sobel kernel is
  1 0 -1
  2 0 -2
  1 0 -1
  now when I try this I am getting just an all black image</p>
  
  <pre><code>float  xVals[9] = {.125,0,-.125,.25,0,-.25,.125,0,-.125};
  Mat xKernel = Mat(3,3,CV_32F,xVals);
  Mat gradXManual,absGradXManual;
  filter2D(Img,gradXManual,-1,xKernel,Point(-1,-1),0,BORDER_DEFAULT);
  convertScaleAbs(gradXManual,absGradXManual);
  imshow("Manual Gradient",absGradXManual);
  </code></pre>
  
  <p>Resulting gradient image is all black. Any ideas what I'm doing wrong? 
  Thanks</p>