理論部分
- 首先 方差的定義是如下
- 基於上公式的較快求解的方式爲:
- 再次簡化爲
- 這個公式前部分理解爲:
reslut_1 = 圖像平方後給圖像進行均值濾波
- 後版本理解爲:
result_2 = 計算均值濾波後在給平方
- 然後
reslut = 根號下(reslut1_1 - resluuut_2)
代碼實現部分
import cv2
import numpy as np
img = cv2.imread("./data/src/222.jpg", True)
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
img = img / 255.0
# 計算均值圖像和均值圖像的平方圖像
img_blur = cv2.blur(img, (21, 21))
reslut_1 = img_blur ** 2
# 計算圖像的平方和平方後的均值
img_2 = img ** 2
reslut_2 = cv2.blur(img_2, (21, 21))
reslut = np.sqrt(np.maximum(reslut_2 - reslut_1, 0))
# reslut_0 = np.sqrt(reslut_2 - reslut_1 )
cv2.imshow('stdfilt', reslut)
cv2.waitKey(0)
cv2.destroyWindow('stdfilt')
結果:
原圖: