| 3 | |
| 4 | |
| 5 | def custom_blur(src): |
| 6 | h, w, ch = src.shape |
| 7 | print("h , w, ch", h, w, ch) |
| 8 | result = np.copy(src) |
| 9 | for row in range(1, h-1, 1): |
| 10 | for col in range(1, w-1, 1): |
| 11 | v1 = np.int32(src[row-1, col-1]) |
| 12 | v2 = np.int32(src[row-1, col]) |
| 13 | v3 = np.int32(src[row-1, col+1]) |
| 14 | v4 = np.int32(src[row, col-1]) |
| 15 | v5 = np.int32(src[row, col]) |
| 16 | v6 = np.int32(src[row, col+1]) |
| 17 | v7 = np.int32(src[row+1, col-1]) |
| 18 | v8 = np.int32(src[row+1, col]) |
| 19 | v9 = np.int32(src[row+1, col+1]) |
| 20 | |
| 21 | b = v1[0] + v2[0] + v3[0] + v4[0] + v5[0] + v6[0] + v7[0] + v8[0] + v9[0]; |
| 22 | g = v1[1] + v2[1] + v3[1] + v4[1] + v5[1] + v6[1] + v7[1] + v8[1] + v9[1]; |
| 23 | r = v1[2] + v2[2] + v3[2] + v4[2] + v5[2] + v6[2] + v7[2] + v8[2] + v9[2]; |
| 24 | result[row, col] = [b//9, g//9, r//9] |
| 25 | cv.imshow("result", result) |
| 26 | |
| 27 | |
| 28 | src = cv.imread("./test.png") |