image - 使用 OpenCV 进行高斯模糊 : only blurring a subregion of an image?

标签 image opencv image-processing computer-vision

是否可以使用 OpenCV 仅模糊图像的一个子区域,而不是整个图像,以节省一些计算成本?

EDIT:重要的一点是,在模糊分区的边界时,尽量使用已有的图片内容;只有当卷积超出原始图像的边界时,才可以使用外推法或其他人工边界条件。

最佳答案

要模糊整个图像,假设您想覆盖原始图像(cv::GaussianBlur 支持就地过滤),您将得到类似

 cv::GaussianBlur(image, image, Size(0, 0), 4);

要模糊一个区域使用 Mat::operator()(const Rect& roi)提取区域:

 cv::Rect region(x, y, w, h);
 cv::GaussianBlur(image(region), image(region), Size(0, 0), 4);

或者如果你想在单独的图像中输出模糊:

 cv::Rect region(x, y, w, h);
 cv::Mat blurred_region;
 cv::GaussianBlur(image(region), blurred_region, Size(0, 0), 4);

上面使用默认的 BORDER_CONSTANT 选项,在进行模糊处理时假设图像外的所有内容都是 0。 我不确定它如何处理区域边缘的像素。您可以强制它忽略区域外的像素 (BORDER_CONSTANT|BORDER_ISOLATE)。所以它认为它可能确实使用了区域外的像素。您需要将上面的结果与以下内容进行比较:

 const int bsize = 10;
 cv::Rect region(x, y, w, h);
 cv::Rect padded_region(x - bsize, y - bsize, w + 2 * bsize, h + 2 * bsize)
 cv::Mat blurred_padded_region;
 cv::GaussianBlur(image(padded_region), blurred_padded_region, Size(0, 0), 4);

 cv::Mat blurred_region = blurred_padded_region(cv::Rect(bsize, bsize, w, h));
 // and you can then copy that back into the original image if you want: 
 blurred_region.copyTo(image(region));

关于image - 使用 OpenCV 进行高斯模糊 : only blurring a subregion of an image?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24195138/

相关文章:

python - 如何将彩色图图像反转为标量值?

facebook - 如何使用图形 API 将图像链接发布到 Facebook feed

OpenCV + 摄影测量

image-processing - 将 3D 图像数据分析为 2D

python-3.x - 如何使用 python 和 PIL 检测图像的特定边框细节并根据它进行裁剪?

android - 禁用 Android 图像自动旋转

R : what library should I use? 中的图像处理/颜色检测

opencv - opencv-如何从几个小图像创建一个大图像?

python - 如何使用python删除图像中人物周围的白色边框/边缘?

python-3.x - 如何识别七段显示器上的数字?