title: Process image smoothing using image Pointer- need help to correct my code
body: <p>i am trying to perform average smoothing by pointers. </p>
  
  <p>My aim is to process image by pointers . </p>
  
  <p>This is what i coded. </p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>int main() {
  
      Mat img = imread("best-testimg.jpg");
  
      Mat src = img.clone();
  
      int const templeteWindowSize = 3;
  
      int tr = templeteWindowSize &gt;&gt; 1; //templateRegion
  
      int bb = tr;                 //backgroundBorder
  
      //create large size image for bounding box;
      Mat im;
      copyMakeBorder(src, im, bb, bb, bb, bb, cv::BORDER_DEFAULT); //left= right= bottom= top = border = bb
  
      //=========================================================
  
      Mat dest = Mat::zeros(src.size(), src.type());
  
      int T = templeteWindowSize * templeteWindowSize;
  
      int count = T - 1;
  
      //step of template to image
      const int cstep = im.step - templeteWindowSize;
  
      for (int j = 0; j &lt; src.rows; j++) {
  
          //src ptr
          uchar* d = dest.ptr(j);
  
          for (int i = 0; i &lt; src.cols; i++) {
  
              uchar* tprt = im.data + im.step*(tr + j) + (tr + i); //pointer of image data amd step at 3x3 
  
              double tweight = 0.0;
              for (int n = templeteWindowSize; n--;)
              {
                  for (int m = templeteWindowSize; m--;)
                  {
                      tweight += *tprt++;
                  }
                  tprt += cstep;
              }
              tweight /= 9;
              *(d++) = (saturate_cast&lt;uchar&gt;(tweight) );
          }//i
  
      }//j    
      imshow("dest", dest);
      waitKey(0);
      return 0;
  }
  </code></pre>
  
  <p><strong>Input Image:</strong> </p>
  
  <p><a href="https://i.stack.imgur.com/f5SRb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f5SRb.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Output Image</strong> </p>
  
  <p><a href="https://i.stack.imgur.com/2PwM4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2PwM4.png" alt="enter image description here"></a></p>
  
  <p>Problem: My image is not processed well by pointers. Can anyone correct my mistake in code. thanks </p>
  
  <p>Can anyone please help me to correct my code. thanks . </p>