Reputation: 1
I am writing a program in c++, the program was to open an image and move the cursor around the image to read the temperature under the cursor. The image has 14 different colour patches and I can read the colour and convert this into a temperature.
The next thing I have to do is produce a method that can visualise the temperature with more resolution, i.e. with more than 14 colour patches. Then draw the new colour patch at the bottom of the GUI on a panel to check if I can visually differentiate the colours for different temperatures in the range from 300K to 30000K.
I am unsure on how to perform this last part. I think it has something to do with converting the RGB values to HSL, but I cant see how this would give me say 28 colour patches.
Any help would be appreciated.
Thanks
Upvotes: 0
Views: 2229
Reputation:
Converting from RGB to HSV is a fancy step that you can try later. I imagine that you want to render what looks like a continuous color gradient:
Am I correct? If you need to render hundreds of colors, but you have only 14 colors at hand, then you will need to blend between adjacent colors, which is called "interpolation."
We're going to try a "linear interpolation" because it's simple. You can try a "bicubic interpolation" later.
Let's say that you're about to render one of the single-color vertical lines in the gradient above. First you need to determine what color it's supposed to be. Let's say that the horizontal position of the vertical line can be between 0 and 99.
Then, you need to find which two of your 14 colors to blend between:
float x = horizontal_position * 13.f / 99.f;
int a = floorf(x);
int b = std::min( 13, a + 1 );
Now you need to blend between the two colors to find the color of the vertical line:
float blend = x - a;
color result = palette[a] * (1-blend) + palette[b] * blend;
"color" in the pseudocode above can be RGB, YUV, HSV, etc. That part is up to you. Beware that HSV is a "nonlinear color space" and therefore blending two HSV colors linearly may produce unexpected results.
Upvotes: 2
Reputation: 67487
I'm not sure I understand exactly what you wish to do, but it kind of sounds like you're looking for an interpolating algorithm to basically enlarge your image, filling in the gaps with values outside the 14 colors the original has.
There are a myriad of such algorithms, but a simple bicubic interpolation should suffice.
Upvotes: 1