From 60b5328f9fd88035194fd6b7380b681ae5e6727e Mon Sep 17 00:00:00 2001 From: pmgyqf3wk Date: Tue, 10 Oct 2023 15:01:22 +0800 Subject: [PATCH] ADD file via upload --- image_out.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 image_out.py diff --git a/image_out.py b/image_out.py new file mode 100644 index 0000000..c1da1fc --- /dev/null +++ b/image_out.py @@ -0,0 +1,23 @@ +from PIL import Image +import numpy as np + +# 读取文件中的坐标 +with open('white_coords.txt') as f: + lines = f.readlines() + +coordinates = [tuple(map(int, line.strip().split(','))) for line in lines] + +# 获取坐标的最大值和最小值来确定图像的大小 +max_x = max(coordinates, key=lambda x: x[0])[0] +max_y = max(coordinates, key=lambda x: x[1])[1] + +# 创建一个全黑的图像 +img = Image.new('L', (max_x+1, max_y+1), 'black') +pixels = img.load() + +# 将文件中的坐标点设为白色 +for x, y in coordinates: + pixels[x, y] = 255 + +# 保存图像 +img.save('output_image.png') \ No newline at end of file