If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
wavelenght to colour
12 posts
• Page 1 of 2 • 1, 2
wavelenght to colour
Anyone tried to play with wavelenght (visible light) to RGB conversion for color usage in FS?
No ruby...?
No ruby...?
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: wavelenght to colour
Where are you suggesting this "wavelength" variable would originate from?
- Perfect Human Interface
- Posts: 643
- Joined: Sun Mar 10, 2013 7:32 pm
Re: wavelenght to colour
I don't understand the question? Colors of visible light have wavelenghts. Colors of flowstone's RGB have 3 values (R-G-B), ranging from 0 to 255. I suppose there are some "curves" (templates based on assumptions) inside the RGB space, that reflect light spectra progression. If you type in google "wavelenght to rgb", you will find data on that, but I don't know how to translate them it into FS language. Besides I assume that someone played with it before me.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: wavelenght to colour
Yes but... even if you create a wavelength to RGB converter, you still have to feed it a wavelength value. Where would that value come from?
- Perfect Human Interface
- Posts: 643
- Joined: Sun Mar 10, 2013 7:32 pm
Re: wavelenght to colour
- Code: Select all
# from http://www.physics.sfasu.edu/astro/color/spectra.html
def rgbFromWavelength(wl, gamma=0.8)
rgb=case wl
when (380..439); [-1.0*(wl-440.0)/(440.0-380.0), 0.0, 1.0]
when (440..489); [0.0, (wl-440.0)/(490.0-440.0), 1.0]
when (490..509); [0.0, 1.0, -1.0*(wl-510.0)/(510.0-490.0)]
when (510..579); [(wl-510.0)/(580.0-510.0), 1.0, 0.0]
when (580..644); [1.0, -1.0*(wl-645.0)/(645-580.0), 0.0]
when (645..780); [1.0, 0.0, 0.0];
end
sss=(wl>700 && 0.3+0.7*(780.0-wl)/(780.0-700.0) ||
wl<420 && 0.3+0.7*(wl-380.0)/(420.0-380.0) ||
1)
rgb.map!{|c| (sss*c)**gamma}
def rgb.to_bytes; self.map{|c| (0xff*c)}; end
def rgb.to_s; ('#'+'%02x'*3)%self.to_bytes; end
rgb
end
sorry in ruby it easy
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: wavelenght to colour
Perfect Human Interface wrote:Yes but... even if you create a wavelength to RGB converter, you still have to feed it a wavelength value. Where would that value come from?
Ah, I see your point. There are various ways, starting from correlative measurements for example. My way is to transcode sound into color, by changing the octaves from sonic wavelenghts into visual ones. I need such specific representation for further testing and experimentation (among my reasons are some forms of synesthesia). Besides I'm curious how it looks like in raw form; mixing sounds is like mixing colors of light (i.e. additive synthesis).
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: wavelenght to colour
Tronic wrote:
- Code: Select all
# from http://www.physics.sfasu.edu/astro/color/spectra.html
def rgbFromWavelength(wl, gamma=0.8)
rgb=case wl
when (380..439); [-1.0*(wl-440.0)/(440.0-380.0), 0.0, 1.0]
when (440..489); [0.0, (wl-440.0)/(490.0-440.0), 1.0]
when (490..509); [0.0, 1.0, -1.0*(wl-510.0)/(510.0-490.0)]
when (510..579); [(wl-510.0)/(580.0-510.0), 1.0, 0.0]
when (580..644); [1.0, -1.0*(wl-645.0)/(645-580.0), 0.0]
when (645..780); [1.0, 0.0, 0.0];
end
sss=(wl>700 && 0.3+0.7*(780.0-wl)/(780.0-700.0) ||
wl<420 && 0.3+0.7*(wl-380.0)/(420.0-380.0) ||
1)
rgb.map!{|c| (sss*c)**gamma}
def rgb.to_bytes; self.map{|c| (0xff*c)}; end
def rgb.to_s; ('#'+'%02x'*3)%self.to_bytes; end
rgb
end
sorry in ruby it easy
Quick question - what is provided as input here (i.e. what value), and what comes from output (shhouldn't there be 3 outs for R-G-B integers?) ? When I paste the code to ruby window, I see no inputs nor outputs related to the formula. Sorry, but I have no idea what to expand it, help
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: wavelenght to colour
you needed to adapt it for use with the primitive I2C,
I made the changes as having 3 separate outputs for RGB values, and a fourth that contains them all in an array.
then copy the code in a ruby module,
set the input to float, sets three output in integer, and the last in integer array.
I made the changes as having 3 separate outputs for RGB values, and a fourth that contains them all in an array.
then copy the code in a ruby module,
set the input to float, sets three output in integer, and the last in integer array.
- Code: Select all
# from http://www.physics.sfasu.edu/astro/color/spectra.html
def event i,v
wl = @in
gamma=0.8
rgb=case wl
when (380..439); [-1.0*(wl-440.0)/(440.0-380.0), 0.0, 1.0]
when (440..489); [0.0, (wl-440.0)/(490.0-440.0), 1.0]
when (490..509); [0.0, 1.0, -1.0*(wl-510.0)/(510.0-490.0)]
when (510..579); [(wl-510.0)/(580.0-510.0), 1.0, 0.0]
when (580..644); [1.0, -1.0*(wl-645.0)/(645-580.0), 0.0]
when (645..780); [1.0, 0.0, 0.0];
end
sss=(wl>700 && 0.3+0.7*(780.0-wl)/(780.0-700.0) ||
wl<420 && 0.3+0.7*(wl-380.0)/(420.0-380.0) ||
1)
rgb.map! {|c| ((sss*c)**gamma) * 255}
output 0, rgb[0] # R
output 1, rgb[1] # G
output 2, rgb[2] # B
output 3, rgb # RGB to Int Array
rgb
end
Last edited by Tronic on Tue Apr 23, 2013 10:50 pm, edited 1 time in total.
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: wavelenght to colour
Okay, works, thanks. Another question - what is the formula for additive mixing of colors (i.e. like mixing the lights)? Is it a matter of just adding the RGB channels from two sources, or some sort of averaging (channels sum / n-channels)?
//edit:
Okay, i see two approaches. One is to take max value from one of channels (thus - mixing RGB produces white). Second is to take average of channels (mixing RGB produces dark grey). Or did I miss something?
I'm curious if there are other RGB mapping systems, or how "accurate" (towards "natural perception") is this one.
//edit:
Okay, i see two approaches. One is to take max value from one of channels (thus - mixing RGB produces white). Second is to take average of channels (mixing RGB produces dark grey). Or did I miss something?
I'm curious if there are other RGB mapping systems, or how "accurate" (towards "natural perception") is this one.
- Attachments
-
- colors.fsm
- (5.01 KiB) Downloaded 1051 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: wavelenght to colour
Adding the RGB values is certainly the conventional way to do it - and results in a colour that usually seems intuitively correct much of the time (e.g. red + yellow = orange)
But there are a couple of things to watch out for...
(NB - this is based on my knowledge of photography; I make no claim of any expertise in optical physics or perceptual models!)
1) Gamut
Whereas in reality, the intensity can just keep on increasing when adding colours, RGB has a max of 255 per channel. This badly effects colours as soon as any one of the channels reaches the max.
Not always easy to deal with - in programs like Photoshop, there are often many choices for rendering out-of-gamut colours. Some purely mathematical - like your idea of averaging to keep the proportions. But others are based on models of eye/brain colour perception, in some cases using the values of surrounding colours to bias the results.
Part of the problem is that the eye's perception of illumination is not linear - whereas RGB and the hardware of monitors is. So a simple averaging doesn't necessarily make a colour which appears to be a darker version of the desired hue.
2) Metamerism
This has to do with the equivalence of colours that are made using two different sets of 'primary' components.
As an example - even the best PC monitor calibration can never make two monitors show EVERY colour exactly the same if the red, green and blue used for the pixels are different between the two. You can get very close, but the gamuts will always be slightly different.
I mention this because, naturally, the cones in our eyes will be tuned to particular RGB components too - which probably aren't the same RGB used on a display.
I have no idea if that would affect your research, but as you are interested in biological/perceptual effects like synaesthesia, it may have some bearing. For example, research has shown that looking at an LCD monitor before bedtime affects the ability to sleep, due to too much of certain blue wavelengths - and also that this effect is not the same as viewing, say, the blue of the sky. So it would seem that precise wavelengths have some importance here, or maybe simply that the artificial light has narrow peaks rather than a diverse spectrum.
Once again, i am answering your questions with more questions - but maybe will lead you to some research that is more based on psychology than Photoshop!
But there are a couple of things to watch out for...
(NB - this is based on my knowledge of photography; I make no claim of any expertise in optical physics or perceptual models!)
1) Gamut
Whereas in reality, the intensity can just keep on increasing when adding colours, RGB has a max of 255 per channel. This badly effects colours as soon as any one of the channels reaches the max.
Not always easy to deal with - in programs like Photoshop, there are often many choices for rendering out-of-gamut colours. Some purely mathematical - like your idea of averaging to keep the proportions. But others are based on models of eye/brain colour perception, in some cases using the values of surrounding colours to bias the results.
Part of the problem is that the eye's perception of illumination is not linear - whereas RGB and the hardware of monitors is. So a simple averaging doesn't necessarily make a colour which appears to be a darker version of the desired hue.
2) Metamerism
This has to do with the equivalence of colours that are made using two different sets of 'primary' components.
As an example - even the best PC monitor calibration can never make two monitors show EVERY colour exactly the same if the red, green and blue used for the pixels are different between the two. You can get very close, but the gamuts will always be slightly different.
I mention this because, naturally, the cones in our eyes will be tuned to particular RGB components too - which probably aren't the same RGB used on a display.
I have no idea if that would affect your research, but as you are interested in biological/perceptual effects like synaesthesia, it may have some bearing. For example, research has shown that looking at an LCD monitor before bedtime affects the ability to sleep, due to too much of certain blue wavelengths - and also that this effect is not the same as viewing, say, the blue of the sky. So it would seem that precise wavelengths have some importance here, or maybe simply that the artificial light has narrow peaks rather than a diverse spectrum.
Once again, i am answering your questions with more questions - but maybe will lead you to some research that is more based on psychology than Photoshop!
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
12 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: Google [Bot] and 45 guests