1

So I am trying to turn my webcam to a simple spectrometer. Because whole process is behind not only camera chip, but also the framework that gets the values I have to work with RGB. This makes me ask myself a question: can I guess the major wavelengths each light consists from?
There will be a piece of CD, or a crystal to break the light beam to pieces, before it reaches the camera, but still I need some self-calibration. And also, I like nice graphs.
Aside from converting RGB, another solution may be generating full spectra as rainbow and comparing RGB to spectra. Is that possible?
Question summary (let me make it clear for downvoters):

  1. How to guess not only dominant color in RGB but also try to guess some composite values (eg. for magenta)?
  2. How to generate rainbow so I can use it to compare it with RGB?

And for those who demand sourcecode example, I am looking for function:

int rgb2wave(int r, int g, int b) {
    /*some code*/
    return wavelength;
}
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • 3
    Why the votedown? I need an answer to this question as well! – Matouš Vrba Feb 21 '13 at 19:55
  • 2
    This has little or nothing to do with a specific programming problem. – Tyler Durden Feb 21 '13 at 20:12
  • 2
    @TylerDurden: Opinion that a programming problem must be represented by some code only shows your weak imagination. Asking problems theoretically does not imply that the solutions will not be implemented as programs. – Tomáš Zato Feb 21 '13 at 20:15
  • There are SE sites for asking theoretical questions, this is not one of them. In fact, the FAQ here states that good questions should be related to the programming part of a problem. – ssube Feb 21 '13 at 20:21
  • see [convert RGB pixel to wavelength](https://stackoverflow.com/a/42542687/2521214) – Spektre Sep 22 '22 at 10:36

1 Answers1

3

If you are using a diffraction grating or a dispersion prism, then it will be the pixel position that determines the wavelength.

The problem with the RGB filters is that they affect the sensitivity of the pixel to a given wavelength. If you want a good estimation of the spectrum, you will need to calibrate the response of red, green, and blue pixels separately.

You may be able to do this by comparing the response of nearby red, green, and blue pixels. Since nearby pixels will be looking at light of nearly the same frequency, you may be able to extract this kind of calibration from looking at a simple near-black-body light source, like an incandescent light bulb.

comingstorm
  • 25,557
  • 3
  • 43
  • 67
  • If the driver or software makes any attempt at white balance compensation you will find that the RGB output is totally uncalibratable. – Mark Ransom Feb 21 '13 at 20:35
  • driver balancing as well as optical filters will be removed or disabled. I'll choose appropriate webcam for this purpose. – Tomáš Zato Feb 21 '13 at 20:51
  • Since community decided that I do not deserve answer to my question (I have read and was not satisfied with the one that is linked as duplicate) I will accept this as answer to reward comingstorms effort at least. – Tomáš Zato Feb 21 '13 at 21:07
  • 1
    @TomášZato, if you had asked the question with a reference to the previous one, with an explanation of why you found it unsatisfactory, you might not have gotten closed. I think that the reason you haven't found a good answer yet is that it's a hard problem. You can always put a bounty on the other question if you want more attention to it, even providing a link back to this question. – Mark Ransom Feb 22 '13 at 06:42
  • @MarkRansom you are completelly right, I will try to start a better question. – Tomáš Zato Feb 22 '13 at 07:47
  • Is it always going to be used to look at the same type of light? I image that reconstructing a completely generaly spectrum with a simple RGB webcam is probably not going to get very far. If for example you know the spectrum is blackbody you could probably have a reasonably guess at the peak and then get the spectrum from theory. If your interested in only single LED's and have access to some decent optical filters then again you may be able to construct a calibration curve. – Bowler Feb 22 '13 at 11:32
  • you cannot convert RGB from camera to wavelength because colors are not wavelengths !!! light of some wavelength have distinct color (primary colors which are btw different for each observer because we do not have the same eyes) but the same color can be also created by a mix of more different wavelengths also ... Also cameras filters 3 distinct wavelengths so you have only info about 3 narrow spectral wavelengths. as mentioned in this answer the only way to go is to have refraction and measure the light pixel position not color – Spektre Mar 04 '14 at 08:17