Board index » cppbuilder » Getting RGB values

Getting RGB values

Hello all:

I have a question about getting RGB values from an image (TImage
component).

I'm working on a program that takes streaming data from a thermal camera,
displays that image in a TImage component as a bitmap.  The image is a
display in colors of different temperatures on the object being viewed. The
purpose of the program is to display the image, allow the user to assign
different temperature values to specific colors, and allow the user to
choose different areas to inspect (by drawing a rectangle, cross or dot)
and receive temperature values (based on the color of the pixels at that
area and the temperatures assigned by the user to colors) for those
inspection areas.

To set the temperature/color relationship, here's what they do:  At the top
of this image, there is a 'calibration strip' of the colors that are
present in the image.  The user can then click on the color they want to
represent 'cold' and assign a temperature to it.  The program will get the
RGB values of the 'cold' color, write those values into an array, along
with the user defined temp.  The user then does the same for the 'hot'
color.  Then, to make matters even more fun, the user can specify a number
of iteration between the cold and hot colors/temperatures.  For instance,
the user can assign blue a 'cold' value of 10 degrees and red a 'hot' value
of 25 degrees, with 5 iterations between those two temps.  That would give
the program the following temperatures to identify RGB values for: 13, 16,
19, 22.  Each of these will obviously have a specific RGB value, with 10
degrees (blue) being (0, 0, 255) and 25 degrees (red) being (255, 0, 0),
with the points in between having various combinations of RGB values.

Now, for the questions:  1) How do I get the RGB values and assign them to
variables that I can write to an array?  2) How would I go about setting
the RGB values for the iterations between the two user defined
colors/temps?  3) How would I account for RGB values that fall between two
colors/temps?  (i.e.., if I have a RGB value that falls between the RGB
values for 10 degrees and 13 degrees, do I have any way to account for
this?)  4) Am I trying to do this the hard way?  Is there an easier way to
do this?  

All help will be greatly appreciated since I know nothing about graphics
programming.

Thanks kindly.

Brett Messimer

PS: If I have not explained this sufficiently, please e-mail me with your
questions and I'll answer them.  

 

Re:Getting RGB values


Quote
"Brett Messimer" <haz...@pa.net> wrote:
>  Now, for the questions:  1) How do I get the RGB values and assign them to
>  variables that I can write to an array?  

This bit is easy, the Canvas object associates has a Pixels property
that can be used. So Canvas->Pixels[x][y] will get a TColor. A TColor
is basically an RGB value.

Quote
> 2) How would I go about setting
>  the RGB values for the iterations between the two user defined
>  colors/temps?  

Not sure. You could try adjusting the RGB values by an amount that
would turn one colour into another. i.e. To go from RGB(255,0,0) to
RGB(0,0,255) you could try Adding RGB(-51,0,51) successively.

Quote
> 3) How would I account for RGB values that fall between two
>  colors/temps?  (i.e.., if I have a RGB value that falls between the RGB
>  values for 10 degrees and 13 degrees, do I have any way to account for
>  this?)  

Interpolation? It's your code!

Robert Chafer

Re:Getting RGB values


Quote
Brett Messimer wrote:
> Now, for the questions:  1) How do I get the RGB values and assign
> them to
> variables that I can write to an array?  2) How would I go about
> setting
> the RGB values for the iterations between the two user defined
> colors/temps?  3) How would I account for RGB values that fall between
> two
> colors/temps?  (i.e.., if I have a RGB value that falls between the
> RGB
> values for 10 degrees and 13 degrees, do I have any way to account for

> this?)  4) Am I trying to do this the hard way?  Is there an easier
> way to
> do this?

Getting the colors between 2 temps?  Thats easy, you will probably want
to use linear interpolation.  Basically, arrays of colors is bad for
this.  What you want is for the user to specify the 2 colors at the
extremes, and then have your program pass a value that is inbetween 0
and 1, 1 being the hot extmreme, and 0 being the cold extreme.  Now you
have to mix the colors based on this ratio.

If your colors are specified in float RGB values, between 0 and 1, you
can use this mixing code.

r3=r1*ratio+r2*(1-ratio)
b3=b1*ratio+b2*(1-ratio)
g3=g1*ratio+g2*(1-ratio)

If you use this code instead of having just a few colors inbetween the
extremes, you will get a look that is 10x better than what you had in
mind before, since this one will use many many many more colors.  Also,
if you are using RGB values of 0-255, then what you do is basically
rewrite the code to type cast your R B G values to float so when you
mutliply by the float, you don't get 0 evertime, and then typecast back
to int/char.  And since you are using a TImage, after you ahve your RGB
tripplet, you are going to have to convert it to hexadecimal.  I'd hate
to take away all of the fun from you, so you can figure out the rest ;)
:)

--
Jason Miller
ja...@tcimet.net

Other Threads