title: creating 3x3 sobel operator in opencv2 C++
body: <p>Im trying to create my own sobel edge detection based off of the gx and gy matrices on three channels i have in my code below.<br>
      [[0,1,2],
       [-1,0,1],
        [-2,-1,0]]
  and</p>
  
  <pre><code>[-2,-1,0],
   [-1,0,1],
   [0,1,2]]
  </code></pre>
  
  <p>I edited the variables j and i in my code further down but it is not working, how can i create a sobel edge detection on those three channels </p>
  
  <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  
  void salt(cv::Mat &amp;image, int n) {
  
  int i,j;
  for (int k=0; k&lt;n; k++) {
  
      // rand() is the MFC random number generator
      i= rand()%image.cols;
      j= rand()%image.rows;
  
  
      if (image.channels() == 1) { // gray-level image
  
          image.at&lt;uchar&gt;(j,i)= 255; 
  
      } else if (image.channels() == 3) { // color image
  
          image.at&lt;cv::Vec3b&gt;(j,i)[0]= 255; 
          image.at&lt;cv::Vec3b&gt;(j-1,i-1)[1]= 255; 
          image.at&lt;cv::Vec3b&gt;(j,i-1)[2]= 255; 
      }
  }
  }
  
  int main()
  {
  srand(cv::getTickCount()); // init random number generator
  
  cv::Mat image= cv::imread("space.jpg",0);
  
  salt(image,3000);
  
  cv::namedWindow("Image");
  cv::imshow("Image",image);
  
  cv::imwrite("salted.bmp",image);
  
  cv::waitKey(5000);
  
  return 0;
  }
  </code></pre>