1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| import numpy as np
import cv2
A = np.array(
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0],
[0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], np.uint8)
Ac = 1 - A
print(A)
print(Ac)
# print(np.pad(Ac, (1, 1), mode='constant', constant_values=(1, 1)))
print()
T1 = np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]], np.uint8)
T2 = np.array([[1, 0, 1], [0, 0, 0], [1, 0, 1]], np.uint8)
img1 = cv2.erode(A, T1)
# 事实上这里是cv2.erode(Ac, T2, borderValue=1)
img2 = cv2.erode(Ac, T2)
print(img1)
print(img2)
print()
print(img1 & img2)
|