Skip to content Skip to sidebar Skip to footer

How To Get Color Temperature From Color Correction Gain

I am trying to find out the Color Temperature of a Photo captured by the Camera. final CameraCaptureSession.CaptureCallback previewSSession = new CameraCaptureSession.CaptureCallba

Solution 1:

Since you have mentioned about apple provided method for achieving the same.

I m starting with Apple documentation on the method

From Apple Documentation

Apple documentation regarding temperatureAndTintValues is as follows

Converts device-specific white balance RGB gain values to device-independent temperature and tint values.

Reference : Documentation by Apple

Same functionality we can implement in android also by following the below methods.

Find out the RGB components in position

int x = (int)event.getX();
int y = (int)event.getY();
int pixel = bitmap.getPixel(x,y);

int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel); 

Correlated Color Temperature (CCT) which is measured in degrees Kelvin (K) on a scale from 1,000 to 10,000.

Following image shows the relation between CCT and some colors enter image description here


Calculating Color Temperature from RGB value

According to the SO Post The Color Temperature can be easily calculated using the following formulas

1. Find out CIE tristimulus values (XYZ) as follows:

X=(−0.14282)(R)+(1.54924)(G)+(−0.95641)(B)
Y=(−0.32466)(R)+(1.57837)(G)+(−0.73191)(B)=Illuminance
Z=(−0.68202)(R)+(0.77073)(G)+(0.56332)(B)

2. Calculate the normalized chromaticity values:

x=X/(X+Y+Z)
y=Y/(X+Y+Z)

3. Compute the CCT value from:

CCT=449n3+3525n2+6823.3n+5520.33

where n=(x−0.3320)/(0.1858−y)

Consolidated Formula (CCT From RGB)

CCT=449n3+3525n2+6823.3n+5520.33
where n=((0.23881)R+(0.25499)G+(−0.58291)B)/((0.11109)R+(−0.85406)G+(0.52289)B)

Android

Implement the same equation using java.

Note: Reference paper

Calculating Color Temperature and Illuminance using the TAOS TCS3414CS Digital Color Sensor


Similar implementations in other platforms

PHP - SO Post

Python - SO Post

Note:

The problem with converting from RGB to color tempperature is that there are approximately 16 million RGB colors, but only a very tiny subset of those colors actually correspond to a color temperature.

For example A green color doesn't correspond to any temperature - it's impossible due to how the human brain perceives light. Remembering that the demo above is really just an approximation, it would be theoretically possible to look up the temperature associated with a given color, but it wouldn't work for most colors.

Why Green is excluded? Read : Why Are There No Purple or Green Stars?


Many of the explanations are taken from other sites,

Hope everything sum up to your need!

Post a Comment for "How To Get Color Temperature From Color Correction Gain"