Skip to content

Implement DN40 algorithm for color temp conversions #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
microbuilder opened this issue Nov 27, 2018 · 10 comments
Closed

Implement DN40 algorithm for color temp conversions #15

microbuilder opened this issue Nov 27, 2018 · 10 comments
Assignees

Comments

@microbuilder
Copy link

The Arduino library was recently updated to include a new RGB to CCT algorithm based on the DN40 app note from Taos (now AMS): adafruit/Adafruit_TCS34725@116a9aa

This function should also be implemented here since it's far more accurate that the current color temperature algorithm.

@ladyada
Copy link
Member

ladyada commented Nov 27, 2018

@caternuson is thjis something you wanna try implementing after TMP006?

@caternuson
Copy link
Contributor

@microbuilder you self assigned. I take that to mean you're wanting to do this update? I could probably code this up, esp. with the Arduino code as a ref. Let me know - don't want to duplicate effort.

@microbuilder
Copy link
Author

@caternuson If you want to have a go at it, feel free! I tried to document the Arduino code as thoroughly as possible, so the thinking behind all the calculations is there but check DN40 for further details.

That Arduino function also does a better job at converting lux, though it isn't used in the Arduino case. But the lux conversion over there should give better results than we have today in the CP code.

@microbuilder
Copy link
Author

There are some potentially useful notes in the comments of that function like ripple rejection, and minimum/maximum thresholds for accurate data if you really want to go overboard on the CP implementation, but it's up to you.

It's worth maintaining the comments as future signposts, though, since they at least highlights some issues you may have with the data.

@caternuson
Copy link
Contributor

Thanks. I'll give it a go then.

I'm not sure this answers the mystery of the origin of color_rgb_bytes though. If you find a reason for why that's there, please let me know. Otherwise I'm thinking it might just disappear as part of this update.

@caternuson caternuson self-assigned this Nov 27, 2018
@microbuilder
Copy link
Author

I suspect it's just a trial and error fudge. The raw RGB values from sensors like this don't have a direct relationship to RGB like we're used to seeing such as #AABBCC on a webpage or 24-bit sRGB values. Each sensor and each photodiode on the sensor will have a distinct response curve, and the 'weight' of each photodiode isn't necessarily equal ... so say red might have a relative weight of 0.7 to green's 1.0, etc.

There is also something described in DN40 called the 'Device Factor' and 'Glass Attentuation' which account for physical characteristics of the sensors and the enclosure of optics the light passes through before it hits the silicon photodiodes. adafruit/Adafruit_TCS34725@116a9aa#diff-3b1fa3e4ed42a3d766e25e7cd51a93aaR421

I think we can just drop this code once a good alternative is found, but I'm 95% certain it is a trial and error best guess. Once we have CCT, it's possible to do a more accurate conversion to a standard RGB working space via CCT->XYZ->sRGB(etc.).

@microbuilder
Copy link
Author

@caternuson I linked to another issue discussing this chip but in Arduino-land, and you can find the DN40 app note there along with an alternative approach converting from raw RGB to XYZ using a 3x3 correlation matrix. The latter approach, however, requires that you also have access to a calibrated spectrometer and the accuracy of the conversion results will depends on the 3x3 correlation matrix you use so it should ideally be done with a specific light source, not a catch-all general purpose 3x3 matrix since LED light is very different spectrally than sunlight, than fluourescent, etc.

Color theory is really interesting to me, but it gets complicated quickly, alas. :P

@caternuson
Copy link
Contributor

OK. Finally got a PR in for this. Check it out. #17

sry this took so long, turns out the endianness of the 16 bit read/write was wrong and wasted tons of time thinking it was my DN40 implementation.

@microbuilder
Copy link
Author

Thanks for the PR! I'll put my comments in #17.

@caternuson
Copy link
Contributor

Closing. DN40 implementation added with #17 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants