Monday, 27 October 2008

Main colours in an image

I need to find out the main colours used in an image for a project.

I have a list of colours that I want to tag the image with - around 30. Ideally I want this to happen automatically, so I need to get information on the colours used in the image.

I already use Image Magick in this project, so may well use this. I think the process will be something like.

1 - Get a histogram of colours in the image.
2 - Specify a range of colours for each of the colours in our list, it is possible these will overlap somewhat.
3 - Calculate the percentage of the image within the range for each colour in the list.
4 - If the colours exceed a given percentage then tag the image with that colour.

Not sure how this will handle highlights and if this is likely to be important. Think if it is we may need to look at some measure of the distance of colours in the image, so we can for example tag an image as red (and grey) if it has thin red stripes on a grey background.

No comments: