Skip to content

Need better RGB color implementation. #18

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
caternuson opened this issue Dec 17, 2018 · 13 comments
Closed

Need better RGB color implementation. #18

caternuson opened this issue Dec 17, 2018 · 13 comments

Comments

@caternuson
Copy link
Contributor

The current implementation of color is in need of replacement. See discussions in #14 and #10 .

@FoamyGuy
Copy link
Contributor

@caternuson Is this still something that is needed? Looking at the PR referenced at the bottom of the issues you linked it looks like this library now matches the the code from that PR.

@caternuson
Copy link
Contributor Author

Yep, that PR was merged. But I think this issue is still open. It relates specifically to the current code in the color function. More specifically, the odd math being done in color_rgb_bytes:

        red   = int(pow((int((r/clear) * 256) / 255), 2.5) * 255)
        green = int(pow((int((g/clear) * 256) / 255), 2.5) * 255)
        blue  = int(pow((int((b/clear) * 256) / 255), 2.5) * 255)

I'm not sure the origins of that are understood. Note how nothing else in the library uses color_rgb_bytes. The other values, like lux and color_temperature use color_raw.

To comply with the CircuitPython Design Guide, a property named color needs to be provided. One idea might be to just use color_raw for that as well. I think things stand at sort of stale mate since the reasoning for color_rgb_bytes is unknown.

@FoamyGuy
Copy link
Contributor

Ah, I understand now. Thank you.

@kattni
Copy link
Contributor

kattni commented May 4, 2020

@FoamyGuy Are you interested in working on this?

@FoamyGuy
Copy link
Contributor

FoamyGuy commented May 5, 2020

@kattni I will try to tackle it. The details of the color computations are a bit over my head but clicking through some of the linked issues and PR threads I found more information and links to other resources.

I can start by trying to use the color_raw value instead of color_rgb_bytes and compare that with the current code.

It seems the header breakouts for this device are out of stock at Adafruit and Digikey currently. https://www.adafruit.com/product/1334

However there is a Flora variant of the sensor breakout also and there are plenty of those available. I will get one ordered to use for testing the changes.

@boukeas
Copy link

boukeas commented Jun 22, 2020

I am pretty sure the pow(x, 2.5) part performs gamma correction and the rest are just normalisation and scaling transforms. However, I am not at all sure about the robustness of these operations and I wasn't able to find a source for them.

@snkYmkrct
Copy link
Contributor

In the projects that use the color sensor, like the Piano Glove, FLORAbrella, and Chameleon Scarf, the Arduino code given uses the raw values from the sensor, normalizes them, and then applies a gamma correction.

I'm pretty sure this is equivalent to the calculations in this issue.

gamma transform

From what I can tell, the code in color_rgb_bytes runs correctly, and there is nothing much to do, except maybe add some comments explaining the calculations done.

I would also suggest adding some extra code to tcs34725_simpletest.py , because at the moment it's not actually showing how to use the sensor to read a color, just the color temperature.

@kattni
Copy link
Contributor

kattni commented Jun 29, 2021

@FoamyGuy @caternuson Do you mind following up with @SilviaCC's suggestion regarding this issue? Thanks!

@kattni
Copy link
Contributor

kattni commented Jun 29, 2021

@SilviaCC Please file another issue for the simpletest update, and if you're interested in doing so, please update the simpletest.py file and submit a PR.

@snkYmkrct
Copy link
Contributor

@kattni Sure, I can do that.

@caternuson
Copy link
Contributor Author

@SilviaCC Excellent sleuthing. @boukeas Seems like you also suggested same.

That does appear to be a baked in gamma correction. @kattni I agree with the general idea of closing this issue as well as PR #31. Adding some code comment would be a good idea. @SilviaCC Do you want to do that as part of PR to update simpletest?

@snkYmkrct
Copy link
Contributor

@caternuson Yes, no problem, I'm working on it (though rather slowly, I'm navigating my first GitHub contribution)

@jposada202020
Copy link
Contributor

Fixed by #37 . Thanks @elpekenin for the heads up :)

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

7 participants