title: OpenCV convolution on ROI
body: <p>I am trying to make a convolution on a region of my image, in just one pixel, to be more exact. I also want that this convolution uses the values outside the ROI, when computing the borders of this ROI. To test this, i wrote the following code.</p>
  
  <pre><code>float kernelData[25] = {0, 0, 0, 0, 0,
                          0, 0, 1, 0, 0,
                          0, 0, 1, 0, 0,
                          0, 0, 0, 0, 0,
                          0, 0, 0, 0, 0};
  
  float imgData[9*9] = {0,  0,  0,   0,   0,    0,  0,   0,  0,
                        0,  0,  0,   0,   0,    0,  0,   0,  0,
                        0,  0,  0,   0,   0,    0,  0,   0,  0,
                        0,  0,  0,   2, 256,  128,  0,   0,  0,
                        0,  0,  0,   4,   1,   64,  0,   0,  0,
                        0,  0,  0,   8,  16,   32,  0,   0,  0,
                        0,  0,  0,   0,   0,    0,  0,   0,  0,
                        0,  0,  0,   0,   0,    0,  0,   0,  0,
                        0,  0,  0,   0,   0,    0,  0,   0,  0};
  
  Mat img = Mat(9, 9, CV_32FC1, (void*)imgData);
  Mat kernel = Mat(5, 5, CV_32FC1, (void*)kernelData);
  Mat window = Mat(img, Rect2i(Point2i(4, 4), Size(1, 1)));
  
  Mat convolved1 = Mat(1, 1, CV_32FC1);
  Mat convolved2 = Mat(1, 1, CV_32FC1);
  Mat convolved3 = Mat(1, 1, CV_32FC1);
  Mat convolved4 = Mat(1, 1, CV_32FC1);
  Mat convolved5 = Mat(1, 1, CV_32FC1);
  
  cv::filter2D(window, convolved1, CV_32F, kernel, Point(-1, -1), 0, BORDER_CONSTANT);
  cv::filter2D(window, convolved2, CV_32F, kernel, Point(-1, -1), 0, BORDER_REPLICATE);
  cv::filter2D(window, convolved3, CV_32F, kernel, Point(-1, -1), 0, BORDER_REFLECT);
  cv::filter2D(window, convolved4, CV_32F, kernel, Point(-1, -1), 0, BORDER_REFLECT_101);
  cv::filter2D(window, convolved5, CV_32F, kernel, Point(-1, -1), 0, BORDER_TRANSPARENT);
  
  cout &lt;&lt; img &lt;&lt; endl;
  cout &lt;&lt; kernel &lt;&lt; endl;
  cout &lt;&lt; window &lt;&lt; endl;
  cout &lt;&lt; convolved1 &lt;&lt; endl;
  cout &lt;&lt; convolved2 &lt;&lt; endl;
  cout &lt;&lt; convolved3 &lt;&lt; endl;
  cout &lt;&lt; convolved4 &lt;&lt; endl;
  cout &lt;&lt; convolved5 &lt;&lt; endl;
  </code></pre>
  
  <p>The execution of this code showed this results:</p>
  
  <pre><code>[0, 0, 0, 0, 0, 0, 0, 0, 0;
   0, 0, 0, 0, 0, 0, 0, 0, 0;
   0, 0, 0, 0, 0, 0, 0, 0, 0;
   0, 0, 0, 2, 256, 128, 0, 0, 0;
   0, 0, 0, 4, 1, 64, 0, 0, 0;
   0, 0, 0, 8, 16, 32, 0, 0, 0;
   0, 0, 0, 0, 0, 0, 0, 0, 0;    
   0, 0, 0, 0, 0, 0, 0, 0, 0;    
   0, 0, 0, 0, 0, 0, 0, 0, 0]
  [0, 0, 0, 0, 0;
   0, 0, 1, 0, 0;
   0, 0, 1, 0, 0;
   0, 0, 0, 0, 0;
   0, 0, 0, 0, 0]
  [1]
  [5]
  [5]
  [5]
  [5]
  [5]
  </code></pre>
  
  <p>I have tested all border types, and none of them get right result, 257.
  I also tried to modify the kernel, changing the positions of 1's and 0's, and the results i have got are always wrong.</p>
  
  <p>The funny part is that this same code runs correctly on my notebook, but in my desktop it does not. </p>
  
  <p>Why is this happening?</p>