Reputation: 73
I'm using the C++ openCV api, and I would like to selectively blur only certain pixels in an image. What is the best way to do this? I was attempting to do it via submatrices, but haven't been able to get it to work.
//5 is the 'radius' i'm blurring (~1/2 kernel width)
cv::Rect srcRect;
srcRect.x = x - 5;
srcRect.y = y - 5;
srcRect.width = 2*5 + 1;
srcRect.height = 2*5 + 1;
cv::Rect dstRect;
dstRect.x = x;
dstRect.y = y;
dstRect.width = 1;
dstRect.height = 1;
cv::Mat src = srcImage(srcRect);
cv::Mat dst = dstImage(dstRect);
cv::blur(src, dst, cv::Size(5,5));
With the above code, nothing changes.
When i set both of the rectangles to srcRect, the sub images are blurred, but the entire dst is blurred then, instead of just the single pixel.
Any ideas?
Upvotes: 1
Views: 3822
Reputation: 1
The input is the original image and blur is the clone image of input
int x1=1,y1=1,x2=200,y2=200;
Rect region(x1, y1, x2, y2);
GaussianBlur(input(region), blur(region), Size(5, 5), x,0);
Upvotes: 0
Reputation: 20056
src
and dst
must be the same size. In your example, dst is a subregion of exactly one pixel.
Your code is correct, besides the way you build rectangles.
Rect srcDstRect(7, 7, 100, 100);
cv::Mat src = srcImage(srcDstRect);
cv::Mat dst = dstImage(srcDstRect);
cv::blur(src, dst, cv::Size(5,5));
Upvotes: 3