<p>If you are interpolating in HSV you will need to handle a few special cases.</p>
<p>If the value of a colour is 0, you should calculate as though the hue and saturation of that colour is the same as the other colour. This means you should use (120, 1, 0) for black in your example.</p>
<p>If a colour has a saturation of 0, you should calculate as though the hue was the same as the hue of the other colour. (If both colours have a saturation of 0 you can use the hue from either.)</p>
<p>If the difference between the two hue values is greater than 180 degrees, you should add 360 to the lower hue value before interpolating. If the resulting interpolated hue is greater than 360, then you should subtract 360 from the interpolated hue.</p>
<p>Alternatively, you could interpolate directly in RGB, which will not require any special cases. This will not give the same interpolated value as HSV, so it depends on how you want the interpolation to work.</p>

CC BY-SA 4.0
2022-09-13T10:42:41.243Z
2022-09-13T10:42:41.243Z
Timothy Maguire
<p>I'm interpolating RGB values by transforming them into HSV space and then back into RGB. I have trouble figuring out how to achieve <code>interpolate(green, black, 0.5) = darkgreen</code>.</p>

<p>Black has multiple representations in HSV, for example <code>(0, 0, 0)</code> and <code>(30, 0, 0)</code> are both black. When I convert the RGB black <code>#000000</code>, I turn it into <code>(0, 0, 0)</code>. When I then interpolate it with green <code>(120, 1, 1)</code>, I get <code>(60, 0.5, 0.5)</code> which is dark semi-saturated yellow. A similar issue exist for white.</p>

<p>Am I supposed to choose a different color space? I don't want to use LAB color space, because it's computationally expensive. How can I make this correct?</p>

<color><interpolation><colorspace>
Interpolating HSV color with black
M.K.
# Interpolating HSV color with black

(Asked by: username_0 on 2020-03-30)

I'm interpolating RGB values by transforming them into HSV space and then back into RGB. I have trouble figuring out how to achieve `interpolate(green, black, 0.5) = darkgreen`.

Black has multiple representations in HSV, for example `(0, 0, 0)` and `(30, 0, 0)` are both black. When I convert the RGB black `#000000`, I turn it into `(0, 0, 0)`. When I then interpolate it with green `(120, 1, 1)`, I get `(60, 0.5, 0.5)` which is dark semi-saturated yellow. A similar issue exist for white.

Am I supposed to choose a different color space? I don't want to use LAB color space, because it's computationally expensive. How can I make this correct?

**Tags:** color, interpolation, colorspace


---

## 1 answers

### Answer by username_1 on 2022-09-13. Score: 2

If you are interpolating in HSV you will need to handle a few special cases.

If the value of a colour is 0, you should calculate as though the hue and saturation of that colour is the same as the other colour. This means you should use (120, 1, 0) for black in your example.

If a colour has a saturation of 0, you should calculate as though the hue was the same as the hue of the other colour. (If both colours have a saturation of 0 you can use the hue from either.)

If the difference between the two hue values is greater than 180 degrees, you should add 360 to the lower hue value before interpolating. If the resulting interpolated hue is greater than 360, then you should subtract 360 from the interpolated hue.

Alternatively, you could interpolate directly in RGB, which will not require any special cases. This will not give the same interpolated value as HSV, so it depends on how you want the interpolation to work.


---

