私は画像と円のゾーンを持っています。私は円のゾーンを除いて、すべてをぼかす必要があります。また、円の輪郭を滑らかにする必要があります。
入力: opencv pythonのグラデーションマスクブレンド
出力は(マスクで画像のredactorでそれを作ったが、私はOpenCVのが唯一のビットマップ・マスクを使用していると思う):今のところ
を私はにISNのpythonのコードを、持っています円の境界がぼやけていない。
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
このコードは、最近1と同様に動作するはずですが、それはしていません。円のイメージはわずかに異なります。それは色にいくつかの問題があります。 質問はまだ開いています。
[THIS PAGE](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
あなたの数式はうまくいきますか? –