平滑图像的特定区域 [英] smoothing in a particular area of image

查看:111
本文介绍了平滑图像的特定区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何在OpenCV中设置投资回报率?

I尝试在图像上使用平滑/模糊滤镜,但仅在源的特定路径/区域中使用。 (目前使用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)

如何做到这一点?

现在我做的事情就像

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

但我想这样做

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

如果更容易,我也可以使用任何ios类。 (还没有找到办法)

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

推荐答案

您可以从原始矩阵中获取子矩阵,例如:

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

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

其中x,y,width,height是子图像的位置。
然后在子矩阵上执行高斯模糊。

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

[edit]
如果你想模糊复杂的形状,一种方法是模糊完整的图像,然后使用mat.copyTo与模糊部分的掩码:

[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);

这篇关于平滑图像的特定区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆