我有一個圖像和圓形區域。我需要模糊所有,除了圈區。另外我需要使圓形的邊界平滑。
輸入: 在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
你的公式的工作效果如何? –