def main():
# Load image and convert it to RGBA, so it contains alpha channel
file_path = sys.argv[1]
name, ext = os.path.splitext(file_path)
im = Image.open(file_path)
im = im.convert('RGBA')
# Go through all pixels and turn each 'green' pixel to transparent
pix = im.load()
width, height = im.size
for x in range(width):
for y in range(height):
r, g, b, a = pix[x, y]
h, s, v = rgb_to_hsv(r, g, b)
min_h, min_s, min_v = GREEN_RANGE_MIN_HSV
max_h, max_s, max_v = GREEN_RANGE_MAX_HSV
if min_h <= h <= max_h and min_s <= s <= max_s and min_v <= v <= max_v:
pix[x, y] = (0, 0, 0, 0)
im.save(name + '.png')
评论列表
文章目录