<blockquote>
<p>How do I calculate average hue, since the numbers loop around?</p>
<p>I will get silly answers sometimes. For example, in HSB/HSL, the average of hue=10 (slightly orange red) and hue=350 (slightly blue red) would arithmetically be hue=(10+350)/2=180 (cyan).</p>
</blockquote>
<ul>
<li><a href="https://stackoverflow.com/q/8169654/3648282">How to calculate mean and standard deviation for hue values from 0 to 360?
</a> <strong>and</strong> <a href="https://stackoverflow.com/q/13959276/3648282">Averaging circular values (particularly Hues in HSL color scheme)</a> which provides C++ source code.</li>
</ul>
<p>What if the values were 0° and 180°, then there are two answers: 90° and 270°; the same thing applies whenever the two inputs are opposite, there's two answers and no clear choice.</p>
<ul>
<li>The program &quot;<a href="http://mkweb.bcgsc.ca/color-summarizer/?download" rel="nofollow noreferrer">Image Color Summarizer</a>&quot; (Linux version) has a file called &quot;peravg.pm&quot; which says: &quot;compute the average and median of a periodic data set, like a set of angles or hues&quot;. The <a href="http://mkweb.bcgsc.ca/color-summarizer/" rel="nofollow noreferrer">main page</a> offers a Windows version and a webpage image upload along with an API.</li>
</ul>
<p>The author explains:</p>
<blockquote>
<p>The colour summarizer will produce descriptive colour statistics for an image. Reported will be the average, median, minimum and maximum of each component of RGB, HSV, LCH and Lab. Average hues are calculated using <a href="https://en.wikipedia.org/wiki/Mean_of_circular_quantities" rel="nofollow noreferrer">mean of circular quantities</a>.</p>
<p>Some of the questions the summarizer will answer are:</p>
<ul>
<li>what is the average color hue, saturation and value in my image?</li>
<li>what are the colours that are most representative of the image?</li>
<li>what is the image's human readable colour description (e.g. dark pure blue)?</li>
<li>what do the RGB, HSV, LCH and Lab histograms look like?</li>
<li>what are the RGB, HSV, LCH and Lab pixel values?</li>
</ul>
</blockquote>
<p>The paper: &quot;<a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3979548/" rel="nofollow noreferrer">Perceiving the average hue of color arrays</a>&quot; (May 1 2014), by Jacquelyn Webster, Paul Kay, and Michael A. Webster examines the subject from the viewpoint of an observer's perception of color.</p>
<p><a href="https://i.sstatic.net/Dq2Ch.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Dq2Ch.png" alt="HSL" /></a></p>

CC BY-SA 4.0
2018-08-30T07:46:17.923Z
2018-08-30T08:26:18.623Z
2020-06-18T08:32:12.800Z
Rob
<p>If I calculate the average (mean) hue of a set of colours naively, I will get silly answers sometimes.</p>

<p>For example, in HSB/HSL, the average of hue=10 (slightly orange red) and hue=350 (slightly blue red) would arithmetically be hue=(10+350)/2=180 (cyan).</p>

<p>Considering the hue channel only, how should I calculate averages in order to get results which match intuition in these cases?</p>

CC BY-SA 4.0
2018-08-29T16:34:25.133Z
Do 350-10=x and 360-350+10=y to get the change in degree if you go clockwise or counter clockwise. Then do 10+x/2 or (10-y/2)%360 depending on which is closest. This assumes your first degree is smaller than the second
Andrew Wilson
CC BY-SA 4.0
2018-08-30T17:17:24.783Z
@Rahul Want to post that as an answer? :)
Nathan Reed
<color><color-science><colorspace>
How do I calculate average hue, since the numbers loop around?
spraff
# How do I calculate average hue, since the numbers loop around?

(Asked by: username_0 on 2018-08-29)

If I calculate the average (mean) hue of a set of colours naively, I will get silly answers sometimes.

For example, in HSB/HSL, the average of hue=10 (slightly orange red) and hue=350 (slightly blue red) would arithmetically be hue=(10+350)/2=180 (cyan).

Considering the hue channel only, how should I calculate averages in order to get results which match intuition in these cases?

**Tags:** color, color-science, colorspace

> **Comments:**
> **username_1**: Do 350-10=x and 360-350+10=y to get the change in degree if you go clockwise or counter clockwise. Then do 10+x/2 or (10-y/2)%360 depending on which is closest. This assumes your first degree is smaller than the second  
> **username_2**: @Rahul Want to post that as an answer? :)  

---

## 1 answers

### Answer by username_3 on 2018-08-30. Score: 2 | Accepted answer

> How do I calculate average hue, since the numbers loop around?
>
> I will get silly answers sometimes. For example, in HSB/HSL, the average of hue=10 (slightly orange red) and hue=350 (slightly blue red) would arithmetically be hue=(10+350)/2=180 (cyan).

* [How to calculate mean and standard deviation for hue values from 0 to 360?](https://stackoverflow.com/q/8169654/3648282) **and** [Averaging circular values (particularly Hues in HSL color scheme)](https://stackoverflow.com/q/13959276/3648282) which provides C++ source code.

What if the values were 0° and 180°, then there are two answers: 90° and 270°; the same thing applies whenever the two inputs are opposite, there's two answers and no clear choice.

* The program "[Image Color Summarizer](http://mkweb.bcgsc.ca/color-summarizer/?download)" (Linux version) has a file called "peravg.pm" which says: "compute the average and median of a periodic data set, like a set of angles or hues". The [main page](http://mkweb.bcgsc.ca/color-summarizer/) offers a Windows version and a webpage image upload along with an API.

The author explains:

> The colour summarizer will produce descriptive colour statistics for an image. Reported will be the average, median, minimum and maximum of each component of RGB, HSV, LCH and Lab. Average hues are calculated using [mean of circular quantities](https://en.wikipedia.org/wiki/Mean_of_circular_quantities).
>
> Some of the questions the summarizer will answer are:
>
> * what is the average color hue, saturation and value in my image?
> * what are the colours that are most representative of the image?
> * what is the image's human readable colour description (e.g. dark pure blue)?
> * what do the RGB, HSV, LCH and Lab histograms look like?
> * what are the RGB, HSV, LCH and Lab pixel values?

The paper: "[Perceiving the average hue of color arrays](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3979548/)" (May 1 2014), by Jacquelyn Webster, Paul Kay, and Michael A. Webster examines the subject from the viewpoint of an observer's perception of color.

[![HSL](https://i.sstatic.net/Dq2Ch.png)](https://i.sstatic.net/Dq2Ch.png)


---

