I am trying to extract the wavelength of a pixel by mapping its R,G,B values (0 to 255) with the individual bandwidths of their visible wavelengths
Here is my current python program
#variable
r, g, b = 245, 122, 155 #let's take RGB value of a pixel
def my_map(x, in_min, in_max, out_min, out_max): #Prominent map function
return int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)
# Map 8 bits value of R,G,B (0 to 255) to their bandwidth of wavelength
R = my_map(r, 0, 255, 499, 700)# rgb 0 = 499 nm, rgb 255 = 700
G = my_map(g, 0, 255, 440 , 580) # rgb 0 = 440 nm, rgb 255 = 580
B = my_map(b, 0, 255, 380, 490) # rgb 0 = 440 nm, rgb 255 = 490
print('\nWavelength of R', r , 'is', R, '\nWavelength of G', g , 'is', G, '\nWavelength of B', b , 'is', B,)
#mean of constituent wavelengths
Wavelength = R+G+B
Wavelength /= 3
print('\nWavelength : ', Wavelength )
The map function is working fine, the individual wavelength value of r or g or b is accurate, but the wavelength is a point value in the entire visible spectrum, etc.
In above code I take average of RGB, but it is not accurate. I know this is not the way.
What should I do for accurate wavelength measurement ?