一、创建np数组
test = np.zeros((3, 3))
for i in range(1, 4):
for j in range(1, 4):
test[i - 1][j - 1] = (i - 1) * 3 + j
改进:
test = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
], dtype=np.uint8)
二、np.uint8函数
从上到下分别是原图,sobelx处理,sobely处理,sobel处理(x+y)。
上图为不用np.unit8转换类型的输出;
下图为用了np.unit8转换类型的输出。
np.unit8可以控制在数组中每个值都限定在0-255范围内:如果小于0,则+256;如果大于255,则-256。