Pixelate Image With Pillow

后端 未结 3 2116
独厮守ぢ
独厮守ぢ 2021-02-09 03:06

I am working on a project where I want to take a picture of a colored grid as an input (made with Lego bricks in this example) and return a much smaller modified picture.

<
3条回答
  •  温柔的废话
    2021-02-09 04:04

    Pixelator does the trick. It is a package based off or rr-s answer. It also has some added benefits for AI and ML applications.

    In bash

    pip install pixelator
    

    in python

    from pixelator import pixelator
    palette = [
        (45,  50,  50),  #black
        (240, 68,  64),  #red
        (211, 223, 223), #white
        (160, 161, 67),  #green
        (233, 129, 76),  #orange
    ]
    
    sensitivity_multiplier = 10
    
    size = (4,4)
    
    output=pixelator(
        in_path='./images/input.jpg',
        palette=palette,
        size=size,
        sensitivity_multiplier=sensitivity_multiplier
        )
    
    output.resize_out_img().save_out_img(path='./images/output.jpg', overwrite=True)
    

提交回复
热议问题