p6 | p7 | p8 |
p4 | p0 | p5 |
p1 | p2 | p3 |
抗混滤波就是加大中心点p0的权重的一个加权平均而已
for y in range(img_pad.shape[0] - 4):
for x in range(img_pad.shape[1] - 4):
p0 = img_pad[y + 2, x + 2]
p1 = img_pad[y, x]
p2 = img_pad[y, x + 2]
p3 = img_pad[y, x + 4]
p4 = img_pad[y + 2, x]
p5 = img_pad[y + 2, x + 4]
p6 = img_pad[y + 4, x]
p7 = img_pad[y + 4, x + 2]
p8 = img_pad[y + 4, x + 4]
aaf_img[y, x] = (p0 * 8 + p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8) / 16