#๐Ÿ”’ How do I find the specific color of an image while accounting for light variations?

34 messages ยท Page 1 of 1 (latest)

dawn echo
#

I have a camera taking a picture of a rubik's cube and I want to be able to see what color each cuboid is. I am currently using the HSV color space and, in theory, this would help differentiate colors. In practice, however, the light variations on each cuboid make it almost impossible to get the right ranges of HSV values to get the correct color. I have a series of if statments that almost works, but only has a 25% accuracy because of light changes. Any ideas on how to possible edit the image to remove all brightness variation and have just the exposed colors?

shrewd swiftBOT
#

@dawn echo

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

lyric herald
#

Can you post an example problematic image + code?

dawn echo
#

To the human eye, the image is quite discernable. But to HSV value, the hues frequently overlap and some cuboids are seen as two. Thus, the really poorly coded if statements that check a variety of hue, satuaration, and value values

#

I realized that doing those complex if statments wouldn't be the best solution lol

lyric herald
#

...uh, it feels barely discernible to me with those lightning conditions and reflections

dawn echo
#

like the bottom cuboids just shine white lol

lyric herald
#

doing manually just to see if I even got the colors right?

dawn echo
#

so are there any color filters or anything that will get just the colors?

dawn echo
#

i might add a light at the top (that side), however i feel like, again, it'll just make the colors look completely white

#

well I think I may have found a solution: taking higher quality images lol

#

new image, i'll try with this

lyric herald
#

much better

#

I'm trying some things, and got this with the previous image so far

#

with the new cube ; feels like it just might work?

dawn echo
#

yeah that definitely looks way better. How exactly did you do that?

merry tendon
#

Would it be possible to adjust the white balance of whatever is taking that picture to make it a little bit less... green? That would probably (I don't actually know it would be, theoretically it would just shift the color ranges you are looking for) make it easier to distinguish colors (especially different shades of white and green)
e.g.:

#

I don't actually know how you would do that using python though, sorry. ๐Ÿ˜…

dawn echo
#

lemme see if it works though

dawn echo
#

these are all the white balance options

#

unfortunately none of them look like the one u sent @merry tendon

dawn echo
merry tendon
#

I mean I cheated and just used photoshop... this is still much better that your original picture imo

elder ember
#

maybe there is a way to take image color histogram and up contrast to fit known present colors?

lyric herald
#

tried just ```py
expected_white = np.array(decompose(0xbcfbb7))
arr = arr * (255 / expected_white)[None, None, :]

arr = np.minimum(arr, 255)


Yeah idk, dropping out of this one - good luck
#

if you haven't yet, remember to look up which methods researchers use for that, solving a rubics cube with robotics is a relatively common research problem iirc?

shrewd swiftBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.