Get dominant colors from image discarding the background

后端 未结 4 845
盖世英雄少女心
盖世英雄少女心 2021-02-02 02:42

What is the best (result, not performance) algorithm to fetch dominant colors from an image. The algorithm should discard the background of the image.

I know I can build

4条回答
  •  孤独总比滥情好
    2021-02-02 03:17

    I would say this problem is closer to "impossible" than "very hard". The only approach to it that I can think of would be to make the assumption that the background of an image is likely to consist of solid blocks of similar colors, while the foreground is likely to consist of smaller blocks of dissimilar colors.

    If this assumption is generally true, then you could scan through the whole image and weight pixels according to how similar or dissimilar they are to neighboring pixels. In other words, if a pixel's neighbors (within some arbitrary radius, perhaps) were all similar colors, you would not incorporate that pixel into the overall estimate. If the neighbors tend to be very different colors, you would weight the pixel heavily, perhaps in proportion to the degree of difference.

    This may not work perfectly, but it would definitely at least tend to exclude large swaths of similar colors.

提交回复
热议问题