Algorithm for determining the color of a photograph

When we look at a photograph of a group of trees, we can determine that the photograph is predominantly green and brown, or for a picture of the sea, we can determine that it is mostly blue.

Does anyone know of an algorithm that can be used to detect noticeable color or color in a photograph?

I can provide a 3D clustering algorithm in RGB space or something like that. I was wondering if anyone knew about the existing technique.

+4
source share
4 answers

Convert an image from RGB to a color space with highlighted brightness and saturation (HSL / HSV) http://en.wikipedia.org/wiki/HSL_and_HSV

Then find the dominant values ​​for the hue component of each pixel. Make a histogram for the hue values ​​of each pixel and analyze in which area of ​​the corner the peaks fall. A large peak in a quadrant between 180 and 270 degrees means, for example, most of the blue image.

There can be several difficulties in determining one dominant color. A pathological example: an image whose left half is blue and the right half is red. Also, a hue will not work very well with shades of gray. Thus, a chessboard image with 50% white and 50% black will have two problems: the hue is arbitrary for a black and white image, and there are two colors that make up exactly 50% of the image.

+4
source

It looks like you want to start by calculating an image histogram or a color histogram . The predominant color will be associated with the peak (highs) in the histogram.

+3
source

You might want to change the image from RGB to indexed, then you can use the normal histogram and detect photos (Matlab does this with rgb2ind (), as you probably already know), and then the problem will be reduced to your regular “finding peaks” in the array. "

Then n = hist (Y, nbins) links the elements in the vector Y to 10 equally spaced containers and returns the number of elements in each container as a row vector.

These values ​​in n will give you the number of elements in each bin. Then it’s just a question with the number of boxes to make them wide enough, and with how many elements in each case will make you consider the mentioned bin the prevailing color, and then take the bins containing these many elements, calculating the index that matches their middle and again converts it to RGB.

Everything that you use for your processing probably has similar functions to those

0
source
  • The average number of pixels in an image.
  • Remove all pixels that are farther from the average color than the standard deviation.
  • GOTO 1 with the remaining pixels until little remains (1 or possibly 1%).

You can also pre-process the image, for example, apply a high-pass filter (removing only very low frequencies) to align the lighting in the photo - http://en.wikipedia.org/wiki/Checker_shadow_illusion

0
source

Source: https://habr.com/ru/post/1369377/


All Articles