<p>You could try some form of color quantization algorithm, which generally extract the most dominant N colors. The one I've seen referenced most is <a href="http://www.leptonica.com/papers/mediancut.pdf" rel="nofollow">modified median cut quantization</a> [.pdf], which is based on <a href="http://dcis.uohyd.ernet.in/~mravi/downloads/CIP/OLD-CIP/Median-cut.doc" rel="nofollow">median cut quantization</a> [.doc]. The benefit to this kind of algorithm is that instead of simply averaging every color in the image, it extracts and discards other highly prominent colors instead of allowing them to pollute the average.</p>

<p>The concept is that color space (RGB space) is partitioned into 3D axis-aligned rectangular regions (the paper calls them vboxes) and iteratively subdivided by splitting vboxes, attempting to leave half of the pixels on each side of the split. The result is color clusters that should correspond to color clusters in the image. The largest color has a strong likelihood of being "perceptually similar" to the image.</p>

<p>There's a <a href="http://lokeshdhakar.com/projects/color-thief/" rel="nofollow">JavaScript implementation and demo of this algorithm called Color Thief</a>.</p>

CC BY-SA 3.0
2015-08-11T15:45:12.683Z
2015-08-11T15:45:12.683Z
John Calsbeek
<p>I'm working on a program to use randomly-selected images as a desktop background.  Now, not all images are the same shape as a computer monitor.  One idea I had for dealing with this is to set a background color that is perceptually similar to the image.  How would I go about finding this color?</p>

<p>Simple RGB averaging doesn't take into account nonlinearities such as monitor gamma, and doesn't deal with the human vision system.</p>

CC BY-SA 3.0
2015-08-11T15:50:17.723Z
It's not your question, but you see commonly on TV that 4:3 images are extended to widescreen by using a blurred and stretched copy in the background. That may work for you.
Jorge Rodriguez
<color><human-vision>
Finding a color perceptually similar to an image
Mark
# Finding a color perceptually similar to an image

(Asked by: username_0 on 2015-08-11)

I'm working on a program to use randomly-selected images as a desktop background. Now, not all images are the same shape as a computer monitor. One idea I had for dealing with this is to set a background color that is perceptually similar to the image. How would I go about finding this color?

Simple RGB averaging doesn't take into account nonlinearities such as monitor gamma, and doesn't deal with the human vision system.

**Tags:** color, human-vision

> **Comments:**
> **username_1**: It's not your question, but you see commonly on TV that 4:3 images are extended to widescreen by using a blurred and stretched copy in the background. That may work for you.  

---

## 1 answers

### Answer by username_2 on 2015-08-11. Score: 3 | Accepted answer

You could try some form of color quantization algorithm, which generally extract the most dominant N colors. The one I've seen referenced most is [modified median cut quantization](http://www.leptonica.com/papers/mediancut.pdf) [.pdf], which is based on [median cut quantization](http://dcis.uohyd.ernet.in/~mravi/downloads/CIP/OLD-CIP/Median-cut.doc) [.doc]. The benefit to this kind of algorithm is that instead of simply averaging every color in the image, it extracts and discards other highly prominent colors instead of allowing them to pollute the average.

The concept is that color space (RGB space) is partitioned into 3D axis-aligned rectangular regions (the paper calls them vboxes) and iteratively subdivided by splitting vboxes, attempting to leave half of the pixels on each side of the split. The result is color clusters that should correspond to color clusters in the image. The largest color has a strong likelihood of being "perceptually similar" to the image.

There's a [JavaScript implementation and demo of this algorithm called Color Thief](http://lokeshdhakar.com/projects/color-thief/).


---

