import numpy as np
# 图像的二值化
def Binarization():
img = Image.open("1.png")
plt.imshow(img)
plt.show()
limg = img.convert('L') #转化成灰度图
threshold = 127
table = []
for i in range(256):
if i < threshold:
table.append(0)
else:
table.append(1)
bimg = limg.point(table, "1")# 二值化自定义阀值
im = np.array(bimg) #将Image图像转化成numpy格式,以便查看图像的详细维度信息
bimg.save("2.jpg")
print(im.shape)