Search code examples
image-processinghsl

how to draw hue component of an image


I extracted the hue component of an image and I need to render it. Hue is angular value ranges [0° - 360°] and it isn't reasonable to normalize it to [0 - 255] using min-max normalization as follows: value = (hue - 0) * 255 / (360 - 0)

Any idea how to normalize the hue values to [0 - 255]? Thanks!


Solution

  • The usual way to normalise from one range to another given the input range [inp_min - inp_max] and output range [out_min - out_max] is to use out = (inp - inp_min) / (inp_max - inp_min) * (out_max - out_min) + out_min

    So, use: value = (hue-0) / (360-0) * (255-0) + 0

    Or more simply: value = hue * 255 / 360

    EDIT

    So from the comments below, I now understand the question. What is really being asked is how to translate a hue value to an RGB triplet. Using the wikipedia page on HSL/HSV as a reference:

    h' = hue/60

    x = (1 - |(h' mod 2) - 1|) * 255

    if (h'<=1) RGB = (255, x, 0)

    else if (h'<=2) RGB = (x, 255, 0)

    else if (h'<=3) RGB = (0, 255, x)

    else if (h'<=4) RGB = (0, x, 255)

    else if (h'<=5) RGB = (x, 0, 255)

    else RGB = (255, 0, x)

    This is, in essence, the HSL calculation with S = 100%, L=50%

    Of course the simplest way, if you do not need to do the calculation yourself, is just to use something like this website.