Attention! This forum will be made read-only by Dec-20. Please migrate to Most of existing active users should've received invitation by e-mail.
Ask Your Question

Create a HSV Range Palette

asked 2018-05-14 05:05:22 -0500

johmarjac gravatar image


I am defining a Color Range using two HSV structs.

inRange() lets me create a mask of these on the current image. Thats fine, however, I wanted to create some kind of Color Palette for those two HSV structs. The color palette should display all colors that are within that range and output those colors in RGB ofc.

Is there someone having an idea how I could do this?


edit retag flag offensive close merge delete


why do you want to do this ? what is the purpose of it ?

berak gravatar imageberak ( 2018-05-14 05:44:51 -0500 )edit

Because my supervisor wants me to do that. We are defining color ranges for different colors and he wants to have a small application where u can provide two hsv structs and get the palette of possible colors.

johmarjac gravatar imagejohmarjac ( 2018-05-14 06:52:40 -0500 )edit

should not be too difficult. just start, and come back, if you run into real problems.

(we won't write your code)

berak gravatar imageberak ( 2018-05-14 06:56:17 -0500 )edit

Nah I dont expect code at all, I just wanted some kind of ideas on how to achieve something like that.

I think I would try by starting to iterate all 3 channels in a nested for loop, convert HSV to RGB and set the pixel somewhere, but isnt that quite a very inefficient way of doing it?

johmarjac gravatar imagejohmarjac ( 2018-05-14 07:06:03 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-05-15 04:04:02 -0500

kbarni gravatar image

Ok, here is a small pseudocode (almost runnable) to start with:

void createPalette(uchar lowerb,uchar upperb)
    Mat palette(100,180,CV_8UC3);
    for each pixel (x,y) in palette {
        if((x>lowerb)&&(x<upperb))active=255 else active=0;
       // for each pixel: hue=x, saturation=max, luminosity=0 (black) if the pixel is inactive<Vec3b>(y,x)=Vec3b(x,255,active); 
    Mat paletteRGB;

To create the color palette, it's best to create it in the HSV space, then transform it to RGB. The Value channel can be used to simulate the thresholding (set the masked pixels to black).

You can modulate the saturation on the Y axis.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools



Asked: 2018-05-14 05:05:22 -0500

Seen: 569 times

Last updated: May 15 '18