2

Possible Duplicate:
How to set ROI in OpenCV?

I'm trying to use a smoothing/blur filter on an image but only in a particular path /area of the source. (Using openCV currently)

How can that be done?

right now I'm doing something like

cv::GaussianBlur(im, newim, cv::Size(5,5),1.5);

But I would like to be doing

cv::GaussianBlur(im, newim, cv::Size(5,5),1.5,MyClosedPath);

I can also use any of the ios classes if it is easier to do. (Haven't found a way for that yet either)

Community
  • 1
  • 1
Avba
  • 14,822
  • 20
  • 92
  • 192

1 Answers1

4

You can get a submatrix out of your original matrix eg:

cv::Mat subMat = originalMatrix(cv::Rect(x, y, width, height));

where x,y, width, height are the position of your subimage. Then perform your gaussian blur on the submatrix.

[edit] If you want to blur complex shapes, one way would be to blur the full image, and then use mat.copyTo with the mask of your blurred parts:

cv::Mat mask = ?; // this should be a CV_8U image with 0 pixels everywhere but where you want to blur the original image
cv::Mat blurred;
cv::gaussianBlur(image, blurred, cv::Size(5,5),1.5);
cv::Mat output = image.clone();
blurred.copyTo(output, mask);
remi
  • 3,914
  • 1
  • 19
  • 37
  • I need to do some more complex shapes (and with "holes") - also how would i combine them back to one image? – Avba Oct 08 '12 at 13:09
  • any change made in the submatrix are also applied to your original matrix. I will edit my answer for your second question – remi Oct 08 '12 at 13:12
  • Let me know if that answered your question by marking it! thx – remi Oct 10 '12 at 07:28