from PIL import Image
import os
import bitstring
image_name = '1.png'
current_path = os.path.dirname(__file__)
im = Image.open(os.path.join(current_path,image_name))
image_width = im.size[0]
image_height = im.size[1]
# load pixel
pim = im.load()
bin_result = ''
for row in range(image_height):
for col in range(image_width):
if pim[col,row][0] == 255:
bin_result += '1'
else:
bin_result += '0'
with open(os.path.join(current_path,'result.jpg'),'wb') as f:
f.write(bitstring.BitArray(bin=bin_result).bytes)
攻防世界red_green;python对图片进行识别,将两种颜色转换文0,1并转成文件脚本,red_green
最新推荐文章于 2023-10-02 15:25:11 发布