from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint.
img = np.array(Image.open('2007_000033.png').convert('L'))
rows, cols = img.shape
for i in range(rows):
for j in range(cols):
if (img[i, j] <= 0):
img[i, j] = 0
else:
img[i, j] = 1
plt.figure("lena")
plt.imshow(img, cmap='gray')
plt.axis('off')
plt.show()
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
[python]根据像素值显示二值图像
最新推荐文章于 2023-05-30 18:09:25 发布