我有一个图像和圆形区域。我需要模糊所有,除了圈区。另外我需要使圆形的边界平滑。
输入: 在opencv python中混合渐变蒙版
输出(与掩模图像编辑者成功了,但我认为OpenCV的是仅使用位图掩模):
现在我在Python代码,这ISN模糊圈子的边界。
def blur_image(cv_image, radius, center, gaussian_core, sigma_x):
blurred = cv.GaussianBlur(cv_image, gaussian_core, sigma_x)
h, w, d = cv_image.shape
# masks
circle_mask = np.ones((h, w), cv_image.dtype)
cv.circle(circle_mask, center, radius, (0, 0, 0), -1)
circle_not_mask = np.zeros((h, w), cv_image.dtype)
cv.circle(circle_not_mask, center, radius, (2, 2, 2), -1)
# Computing
blur_around = cv.bitwise_and(blurred, blurred, mask=circle_mask)
image_in_circle = cv.bitwise_and(cv_image, cv_image, mask=circle_not_mask)
res = cv.bitwise_or(blur_around, image_in_circle)
return res
当前版本:
我怎么能模糊圈的边界?在输出的例子中,我在程序中使用了渐变遮罩。在opencv中有类似的东西吗?
UPDATE 04.03
所以,我从this answered topic试图公式和我有什么:
代码:
def blend_with_mask_matrix(src1, src2, mask):
res = src2 * (1 - cv.divide(mask, 255.0)) + src1 * cv.divide(mask, 255.0)
return res
此代码应工作作为最近类似,但它不会。圆圈中的图像稍有不同。它有一些颜色问题。 问题仍然存在。
看看[这页](http://stackoverflow.com/questions/30101044/how-to-blur-some-portion-of-image-in-android) –
@Jeru我已经找到了适当的公式,但有一些问题将其整合到python中。 '(mask/255)* blur +(1-mask/255)*另一个img'。我正在努力工作,没有循环,只有内置numpy矩阵操作 – 01ghost13
你的公式的工作效果如何? –