The fastest way to detect the primary color in an image?

I don’t really like using a language or library, but a tool that does the job well and fast enough. Or perhaps an algorithm or approach to use.

Any advice, code code examples, URL links are welcome.

+3
source share
3 answers

Select a pixel at random. Color is the primary color of your image. It is relatively fast and insanely hopeless.

Select 2 pixels at random. Take the "color mode" of the two. A bit slower, less wildly hopeless.

Select 3 pixels, ...

you can see where it goes

+2
source

, , - 1x1, , 2x2 . , , .

+1

With the Python Imaging Library, you can convert an image to a limited palette and then ask it about colors. Something like (did not check the following):

from PIL import Image
im = Image.open("foo.jpg")
im = im.convert("P", Image.ADAPTIVE, colors=16)

C Image.ADAPTIVE, im.convertselects the 16 most common colors, also known as the palette. Then you can access them using im.palette.

+1
source

All Articles