Algorithm challenge: Generate color scheme from an image

前端 未结 11 1749
猫巷女王i
猫巷女王i 2020-12-02 05:02

Background

So, I\'m working on a fresh iteration of a web app. And, we\'ve found that our users are obsessed with being lazy. Really lazy. In fact, the more wor

11条回答
  •  伪装坚强ぢ
    2020-12-02 05:29

    Below are some suggestions and discussion around different approaches for generating a color scheme from an image:

    First, embed/plot your pixels in some color space. This can be RGB, HSL, or some other color space. Then you can use one of the following to generate a color scheme:

    1. Creating a histogram of the color space - This involves splitting the space into a grid, and counting the pixels in each grid cell. Select the top N cells (histogram buckets) with the most pixels, and average the pixels in each to produce a color per cell. This can be your color scheme.

    2. Median Cut or some other space partitioning technique - This is a nice improvement over #1, as it will split the space by looking at the data.

    3. Clustering Pixels - Cluster the pixels into groups using one of many clustering techniques (k-means, mean-shift, etc.). Then average the pixels in each group to generate a color scheme.

    I wrote a more detailed post on the three above approaches here

    I also wrote an interactive web app that allows you to load an image an create generate a color palette using one of the above three approaches. You can find the code for it on github

提交回复
热议问题