Question

I am pretty new to these things, I have implemented a code in C++ to find HSV values from RGB values.

R = 255;
G = 0;
B = 0;

for this i am getting the value of HSV as :

H = 0;
S = 1;
V = 1;

No i am taking here V= 255V and S = 255S whereas H = H/2. I am getting correct hsv values but i dont know how to plot them in 24 bit bitmap image. I have searched internet but could bot find. Anybody can help me out here ? Thankx

Was it helpful?

Solution

Most image formats (including bitmap) store values in RGB format (or BGR format, depending on endianness). In the case of a 24-bit bitmap, you use 8 bits for red, 8 bits for green, and 8 bits for blue, so if you want to store an image in this format, you'll have to work in RGB (or convert to RGB before saving) for the image to be colored correctly.

Now, if you don't care how the image appears, but just want to store the H, S, and V components in the image's R, G, and B channels, you can easily do so (just scale the chanels up to the desired range). So for a 24-bit bitmap, 8 bits per channel means the channels have a value between 0 and 255. Assuming H, S, and V are in the range 0 to 1, you would multiply each by 255 to put them in that range.

Below are the H, S, and V values of the Stack Overflow logo stored in an images's R, G, and B channels, respectively.

HSV in RGB channels example

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top