remove_green.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:gif-disco 作者: futurice 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号