Pixelate Image With Pillow

后端 未结 3 2068
独厮守ぢ
独厮守ぢ 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 03:48

    Just for fun, I tackled this with ImageMagick - which is also callable from Python...

    First off, I create a little custom palette to match your colours - your white is not very white and your green is different from ImageMagick's idea of green so I used hex for them instead of colour names.

    convert xc:black xc:red xc:"rgb(200,200,200)" xc:"rgb(168,228,23)"  xc:orange +append palette.png
    

    If I scale that palette up, it looks like this:

    enter image description here

    Then I resize your image down to 4x4 and map the result to the custom palette and scale it back up so you can see it like this:

    convert lego.jpg -resize 4x4! +dither -remap palette.png -scale 1600 result.png
    

    and here is the result

    enter image description here

    The white is off to match the "white" in your original.

提交回复
热议问题