答案 0 :(得分:0)
。
from PIL import Image, ImageDraw
IMAGE = 't5XM4.png'
IMAGE_MAP = 'Gz8b7.png'
IMAGE_OUTPUT = 'Result.png'
GREEN = (0, 255, 0)
OFFSET = 10
image_map = Image.open(IMAGE_MAP)
image = Image.open(IMAGE)
pixels = image_map.load()
size_sm = image_map.size
size = image.size
ratio = (size_sm[0]/size[0], size_sm[1]/size[1])
x_list = []
y_list = []
for x in range(size_sm[0]):
for y in range(size_sm[1]):
if pixels[x, y] == GREEN:
x_list.append(x)
y_list.append(y)
draw = ImageDraw.Draw(image)
draw.rectangle(((min(x_list)/ratio[0]-OFFSET, min(y_list)/ratio[1]-OFFSET),
(max(x_list)/ratio[0]+OFFSET,max(y_list)/ratio[1]+OFFSET)),
width=5, outline=GREEN)
image.save(IMAGE_OUTPUT, 'PNG')