thunder44
asked on
Calculate RGB for False Color Map
HI,
I think we've all seen false color maps, say maps of
the USA with different elevations assigned different colors,
say from a red for high altitudes down through the spectrum to Blue or even Purple for low altitudes.
I'm trying to figure out how to calculate RGB values for
say the Red down to the Blue values, with 255 intervals.
I was thinking of using a colorpicker App to grab these
off an existing map, but you'd never get exactly 255 values
evenly spaced.
There must be a way to calculate a 255 value spectrum of RGB values from Red Though Blue.
Any comments or references to code out there on the web appreciated.
I think we've all seen false color maps, say maps of
the USA with different elevations assigned different colors,
say from a red for high altitudes down through the spectrum to Blue or even Purple for low altitudes.
I'm trying to figure out how to calculate RGB values for
say the Red down to the Blue values, with 255 intervals.
I was thinking of using a colorpicker App to grab these
off an existing map, but you'd never get exactly 255 values
evenly spaced.
There must be a way to calculate a 255 value spectrum of RGB values from Red Though Blue.
Any comments or references to code out there on the web appreciated.
I hope to understand what you need ...
dim colMap(0 to 255) as long
for j = 0 to 255
colmap(j) = rgb(255-j,0,j)
next
dim colMap(0 to 255) as long
for j = 0 to 255
colmap(j) = rgb(255-j,0,j)
next
I think I see what you're saying, but I'm afraid that to get the results you're looking for, you're going to have to come up with a color palette. Basically, you've got a grescale heightmap (0-255) that you want to have colored fading from one color to the other. You'd have to change your bitmap to a 256 color bitmap, and add the color palette for the equivilent colors from 0-255.
-Javin
-Javin
ASKER
Heres an example:
http://www.ima.umn.edu/~arnold/interpolation/interpolation.html
see "black-hole-2d-contour.gif "
Another Example:
http://aol.wff.nasa.gov/aoltm/projects/beachmap/97results/970917calvert/
Look at the picture next to "Cliff Region"
Notice the multicolored bar in both pictures. I need to draw, say on a form or in a picturebox, a bar like this. It has to have 255 color shades in it, in a spectrum like the bar in the Examples.
Calculating the correct RGB values to create the bar is the problem.
http://www.ima.umn.edu/~arnold/interpolation/interpolation.html
see "black-hole-2d-contour.gif
Another Example:
http://aol.wff.nasa.gov/aoltm/projects/beachmap/97results/970917calvert/
Look at the picture next to "Cliff Region"
Notice the multicolored bar in both pictures. I need to draw, say on a form or in a picturebox, a bar like this. It has to have 255 color shades in it, in a spectrum like the bar in the Examples.
Calculating the correct RGB values to create the bar is the problem.
It shouldn't be too difficult (fading). You just need to know the start/end positions for the r,g and b values.
I recently did a question on something similar to this... worth a look to get a basic understanding:
https://www.experts-exchange.com/questions/20947594/Algorythm-which-will-display-all-RGB-colors-in-a-Picture-box.html
Private Sub Form_Load()
Me.Visible = True
'Autoredraw=true so the lines will paint...
Me.AutoRedraw = True
'Call painting sub...
Call DrawFade
End Sub
Private Sub DrawFade()
Dim iR As Integer, iG As Integer, iB As Integer, lRGB As Long
iR = 255
iG = 0
iB = 0
Do Until iR = 0
lRGB = RGB(iR, iG, iB)
'Just draw a line on form for testing...
Form1.Line (iB * 15, 0)-(iB * 15, 20 * 15), lRGB
'Increment/Decrement R,G and B values how you require..
'this will just have R go from 255 to 0 and B go from
'0 to 255.. G is not used so the fade will be from red
'to purplish to blue (no green since it's not used)
iR = iR - 1
iB = iB + 1
Loop
End Sub
I recently did a question on something similar to this... worth a look to get a basic understanding:
https://www.experts-exchange.com/questions/20947594/Algorythm-which-will-display-all-RGB-colors-in-a-Picture-box.html
Private Sub Form_Load()
Me.Visible = True
'Autoredraw=true so the lines will paint...
Me.AutoRedraw = True
'Call painting sub...
Call DrawFade
End Sub
Private Sub DrawFade()
Dim iR As Integer, iG As Integer, iB As Integer, lRGB As Long
iR = 255
iG = 0
iB = 0
Do Until iR = 0
lRGB = RGB(iR, iG, iB)
'Just draw a line on form for testing...
Form1.Line (iB * 15, 0)-(iB * 15, 20 * 15), lRGB
'Increment/Decrement R,G and B values how you require..
'this will just have R go from 255 to 0 and B go from
'0 to 255.. G is not used so the fade will be from red
'to purplish to blue (no green since it's not used)
iR = iR - 1
iB = iB + 1
Loop
End Sub
ASKER
Thanks for the replys, if I modify zzzzzoo's code above:
'0 to 255.. G is not used so the fade will be from red
'to purplish to blue (no green since it's not used)
iR = iR - 1
iB = iB + 1
iG = iG + iB '<<<<<<<Added this line
Loop
End Sub
I get a pretty good spectrum. Theres 255 values there, but they don't
appear to be unique. If I just print out the RGB combinations to the form I note values like rgb(210,1035,45) and rgb(209,1081,46). First theres no RGB values over 255, Secondly these two examples seem to yeild the same yellow color if I use them to set the BackColor of a Picturebox to see them side by side.
Recently used a colorpicker to pick out 109 unique colors out of the second example picture spectrum bar. I suppose its possible that thats the best you can do with RGB values.
mmusante's code if modified a bit produces the same two color fade as the original zzzzzooc code.
'0 to 255.. G is not used so the fade will be from red
'to purplish to blue (no green since it's not used)
iR = iR - 1
iB = iB + 1
iG = iG + iB '<<<<<<<Added this line
Loop
End Sub
I get a pretty good spectrum. Theres 255 values there, but they don't
appear to be unique. If I just print out the RGB combinations to the form I note values like rgb(210,1035,45) and rgb(209,1081,46). First theres no RGB values over 255, Secondly these two examples seem to yeild the same yellow color if I use them to set the BackColor of a Picturebox to see them side by side.
Recently used a colorpicker to pick out 109 unique colors out of the second example picture spectrum bar. I suppose its possible that thats the best you can do with RGB values.
mmusante's code if modified a bit produces the same two color fade as the original zzzzzooc code.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
take a look here (http://dev.midar.com/Tutorials/Computers/Programming/VB/HSVtoRGB.asp)
download the zip file you can find a lot of useful color handling utilities inside ...
i think you can use the HSV function inside this project in this way ...
dim colMap(0 to 255) as long
for j = 0 to 255
colmap(j) = hsv(j,1,1)
next
this will produce a kind of red -> blue fade
download the zip file you can find a lot of useful color handling utilities inside ...
i think you can use the HSV function inside this project in this way ...
dim colMap(0 to 255) as long
for j = 0 to 255
colmap(j) = hsv(j,1,1)
next
this will produce a kind of red -> blue fade
ASKER
zzzzzooc's comment about not fitting a smooth fade into only 255 values is correct.
Had a chance to modify zzzzzooc's code a bit more:
Private Sub DrawFade()
Dim iR As Integer, iG As Integer, iB As Integer, lRGB As Long
iR = 255
iG = 0
iB = 0
Do Until iG = 255
lRGB = RGB(iR, iG, iB)
frmDrawFade1.Line (iG * 15, 0)-(iG * 15, 30 * 15), lRGB
iG = iG + 1
Loop
iR = 255
iG = 255
iB = 0
Do Until iB = 255
lRGB = RGB(iR, iG, iB)
frmDrawFade1.Line (iB * 15, 500)-(iB * 15, 30 * 15 + 500), lRGB
iR = iR - 1
iB = iB + 1
Loop
iR = 0
iG = 255
iB = 255
Do Until iG = 0
lRGB = RGB(iR, iG, iB)
frmDrawFade1.Line (iG * 15, 1000)-(iG * 15, 30 * 15 + 1000), lRGB
iG = iG - 1
Loop
iR = 0
iG = 0
iB = 255
Do Until iB = 0
lRGB = RGB(iR, iG, iB)
frmDrawFade1.Line (iB * 15, 1500)-(iB * 15, 30 * 15 + 1500), lRGB
iR = iR + 1
iB = iB - 1
Loop
End Sub
Noticed on the second example picture I mentioned that the color bar is not a smooth fade. I noticed that the RGB values were in four sections of fades. The Sub above recreates these four sections. (note the last two are reversed due to variable deincrementation). You start at Red , go though the spectrum and end back up at red again. If you wanted to create a Fade through the spectrum, within 255 values, you would, as zzzzzooc suggests, have to do a sort of step thu the values at increments.
What I wanted in the first place are more or less evenly spaced colors/RGB values over a 255 range. Now that I understand what that range is (the 4 sections that if lined up properly represent the spectrum colors/RGB values), getting that won't be a problem.
Had a chance to modify zzzzzooc's code a bit more:
Private Sub DrawFade()
Dim iR As Integer, iG As Integer, iB As Integer, lRGB As Long
iR = 255
iG = 0
iB = 0
Do Until iG = 255
lRGB = RGB(iR, iG, iB)
frmDrawFade1.Line (iG * 15, 0)-(iG * 15, 30 * 15), lRGB
iG = iG + 1
Loop
iR = 255
iG = 255
iB = 0
Do Until iB = 255
lRGB = RGB(iR, iG, iB)
frmDrawFade1.Line (iB * 15, 500)-(iB * 15, 30 * 15 + 500), lRGB
iR = iR - 1
iB = iB + 1
Loop
iR = 0
iG = 255
iB = 255
Do Until iG = 0
lRGB = RGB(iR, iG, iB)
frmDrawFade1.Line (iG * 15, 1000)-(iG * 15, 30 * 15 + 1000), lRGB
iG = iG - 1
Loop
iR = 0
iG = 0
iB = 255
Do Until iB = 0
lRGB = RGB(iR, iG, iB)
frmDrawFade1.Line (iB * 15, 1500)-(iB * 15, 30 * 15 + 1500), lRGB
iR = iR + 1
iB = iB - 1
Loop
End Sub
Noticed on the second example picture I mentioned that the color bar is not a smooth fade. I noticed that the RGB values were in four sections of fades. The Sub above recreates these four sections. (note the last two are reversed due to variable deincrementation). You start at Red , go though the spectrum and end back up at red again. If you wanted to create a Fade through the spectrum, within 255 values, you would, as zzzzzooc suggests, have to do a sort of step thu the values at increments.
What I wanted in the first place are more or less evenly spaced colors/RGB values over a 255 range. Now that I understand what that range is (the 4 sections that if lined up properly represent the spectrum colors/RGB values), getting that won't be a problem.
ASKER
Decided to close the question. Split the points between zzzzzooc and mmusante. Pretty much a dead heat, zzzzzooc's code got my brain whirring, mmusantes references were excellent. HSV is something I need to check out. Thanks also to EDDYKT anf Javin007.
ASKER
Heres a version of the Sub that uses the first 3 fade sections to create a Spectrum fade from red at one end to blue on the other. You can use the purple area on the fourth section but the math is more complex to end up with exactly 255 colors.
Private Sub DrawFade()
Dim iR As Integer, iG As Integer, iB As Integer, inc As Integer, lRGB As Long
Dim FadeArray(3, 255) As Integer
'Each one of the three 'Do Until' loops goes thru 85
'increments. 85 * 3 = 255
'three 85 element sections of evenly incremented
'colors shown at top, put together at bottom into
'spectrum of 255 color values
'Note array wastes space by keeping some values that
'don't change
iR = 255
iG = 0
iB = 0
Do Until iG = 255
inc = inc + 1
lRGB = RGB(iR, iG, iB)
frmDrawFade3.Line (iG * 30, 0)-(iG * 30, 10 * 30), lRGB
iG = iG + 3
FadeArray(1, inc) = iR
FadeArray(2, inc) = iG
FadeArray(3, inc) = iB
Loop
iR = 255
iG = 255
iB = 0
Do Until iB = 255
inc = inc + 1
lRGB = RGB(iR, iG, iB)
frmDrawFade3.Line (iB * 30, 500)-(iB * 30, 10 * 30 + 500), lRGB
iR = iR - 3
iB = iB + 3
FadeArray(1, inc) = iR
FadeArray(2, inc) = iG
FadeArray(3, inc) = iB
Loop
iR = 0
iG = 255
iB = 255
Do Until iG = 0
inc = inc + 1
lRGB = RGB(iR, iG, iB)
frmDrawFade3.Line (iG * 30, 1000)-(iG * 30, 10 * 30 + 1000), lRGB
iG = iG - 3
FadeArray(1, inc) = iR
FadeArray(2, inc) = iG
FadeArray(3, inc) = iB
Loop
For inc = 1 To 255
iR = FadeArray(1, inc)
iG = FadeArray(2, inc)
iB = FadeArray(3, inc)
lRGB = RGB(iR, iG, iB)
frmDrawFade3.Line (inc * 30, 1500)-(inc * 30, 10 * 30 + 1500), lRGB
Next inc
End Sub
Private Sub DrawFade()
Dim iR As Integer, iG As Integer, iB As Integer, inc As Integer, lRGB As Long
Dim FadeArray(3, 255) As Integer
'Each one of the three 'Do Until' loops goes thru 85
'increments. 85 * 3 = 255
'three 85 element sections of evenly incremented
'colors shown at top, put together at bottom into
'spectrum of 255 color values
'Note array wastes space by keeping some values that
'don't change
iR = 255
iG = 0
iB = 0
Do Until iG = 255
inc = inc + 1
lRGB = RGB(iR, iG, iB)
frmDrawFade3.Line (iG * 30, 0)-(iG * 30, 10 * 30), lRGB
iG = iG + 3
FadeArray(1, inc) = iR
FadeArray(2, inc) = iG
FadeArray(3, inc) = iB
Loop
iR = 255
iG = 255
iB = 0
Do Until iB = 255
inc = inc + 1
lRGB = RGB(iR, iG, iB)
frmDrawFade3.Line (iB * 30, 500)-(iB * 30, 10 * 30 + 500), lRGB
iR = iR - 3
iB = iB + 3
FadeArray(1, inc) = iR
FadeArray(2, inc) = iG
FadeArray(3, inc) = iB
Loop
iR = 0
iG = 255
iB = 255
Do Until iG = 0
inc = inc + 1
lRGB = RGB(iR, iG, iB)
frmDrawFade3.Line (iG * 30, 1000)-(iG * 30, 10 * 30 + 1000), lRGB
iG = iG - 3
FadeArray(1, inc) = iR
FadeArray(2, inc) = iG
FadeArray(3, inc) = iB
Loop
For inc = 1 To 255
iR = FadeArray(1, inc)
iG = FadeArray(2, inc)
iB = FadeArray(3, inc)
lRGB = RGB(iR, iG, iB)
frmDrawFade3.Line (inc * 30, 1500)-(inc * 30, 10 * 30 + 1500), lRGB
Next inc
End Sub
http://oldlook.experts-exchange.com/questions/20947617/Get-the-amount-of-red-green-and-blue-from-given-32-bit-pixel-value.html