title: Setting border type for opencv c++ function: erode()
body: <p>I need to apply OpenCV functions <code>dilate()</code> and <code>erode()</code> to a <code>Mat</code> object which is in fact an ROI within a bigger image. <code>Mat roiImg</code>  is generated by creating a header for an ROI inside the original image <code>img</code>:</p>
  
  <pre><code>Mat img = imread(...);
  Mat roiImg = img (Rect(...));
  </code></pre>
  
  <p>This is the list of arguments for <code>erode()</code>:</p>
  
  <pre><code>void erode(InputArray src, OutputArray dst, InputArray kernel, Pointanchor=Point(-1,-1), int iterations=1, int borderType=BORDER_CONSTANT, const Scalar&amp; borderValue=morphologyDefaultBorderValue() )
  </code></pre>
  
  <p>The problem is that since my input image to functions erode/dilate is a header for an ROI, it seems that choosing <code>BORDER_CONSTANT</code> as the border type along with the border value equal to <code>morphologyDefaultBorderValue()</code> doesn't have any impact and the border values are obtained from the original image.</p>
  
  <p>Then I found this in the documentation for <code>copyMakeBorder()</code>:</p>
  
  <blockquote>
    <p>When the source image is a part (ROI) of a bigger image, the function will try to use the pixels outside of the ROI to form a border. To disable this feature and always do extrapolation, as if <code>src</code> was not a ROI, use borderType | <code>BORDER_ISOLATED</code>.</p>
  </blockquote>
  
  <p>However, <code>cv::borderInterpolate()</code> which is the function called from within <code>erode()</code> function, doesn't accept <code>BORDER_ISOLATED</code> as a valid border type!</p>
  
  <p>For now, to get around this problem, I have to clone <code>roiImg</code>, and then call <code>erode()</code>. But ideally I do not want the overhead of cloning. Is there any way to get around this?</p>