How can I generate a palette of prominent colors from an image?

后端 未结 6 2142
被撕碎了的回忆
被撕碎了的回忆 2020-12-23 14:57

I\'m trying to figure out how to sample all of the pixels in an image and generate a palette of colors from it, something like this or this. I have no idea where to even beg

6条回答
  •  借酒劲吻你
    2020-12-23 15:27

    The answers involving the code show you how to get the full palette. If you want to get the average colors like in the websites you posted, this is how I would do it.

    Source Image:

    Source

    First, I would average the colors by applying a lowpass filter (something like a Gaussian Blur)

    enter image description here

    That way you are limiting the total palette. From there I would divide the screen into N blocks (N being the total number of pixels you want in your palette)

    enter image description here

    From there, target each block and iterate over each pixel, and get the average pixel for that block and add it to your palette index. The result is something like this:

    enter image description here

    That way your palette is limited and you get the average colors from the different regions. You can do all of that in code, and if you'd like some help with that, let me know and I'll post some. This is just the High Level "what I would do".

提交回复
热议问题