概述

1
2
graph TD
A(取2*2像素格为单位)-->B(计算8邻域区分度)-->C(统计每单位区分度大于阈值的个数)-->D(将计数为0的单位设为255)

素材

image-20230307095354049

计算区分度

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def get_dif(img):
raw, col = img.shape
dif = np.zeros((raw - 1, col - 1, 8), dtype=int)

for i in range(raw - 1):
for j in range(col - 1):
for m in range(8):
d = get_1D_2_2D(m)
if(i + d[0] >= 0 and i + d[0] + 1 <= raw - 1 and j + d[1] >= 0 and j + d[1] + 1 <= col -1):
dif[i][j][m] = abs(int(img[i][j]) - int(img[i + d[0]][j + d[1]])) + \
abs(int(img[i][j + 1]) - int(img[i + d[0]][j + d[1] + 1])) + \
abs(int(img[i + 1][j + 1]) - int(img[i + d[0] + 1][j + d[1] + 1])) + \
abs(int(img[i + 1][j]) - int(img[i + d[0] + 1][j + d[1]]))
return dif

统计

1
2
3
4
5
6
7
8
9
10
11
12
def get_cmp_e(dif, e):
row, col, m = dif.shape
cnt = np.zeros((row, col), dtype=int)

for i in range(row):
for j in range(col):
cnt0 = 0
for k in range(m):
if dif[i][j][k] > e:
cnt0 += 1
cnt[i][j] = int(cnt0)
return cnt

可视化

image-20230307095754792

完整代码及数据

https://gitee.com/icvuln/server_backup_denoise18/tree/master/dif_max