-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
ofColor subtraction and negative values #1144
Comments
A case could be argued for each implementations, actually. Perhaps we need an explicit clamping subtraction operator as well. |
i would say this is a bug, since the behavior is counter-intuitive. opencv deals with this via the this is probably a bug for most math that happens inside ofColor, maybe the best solution is to do something similar to also, @DamianNZ can you give an example of a situation where using non-clamping operators is important? the one i can think of is when you want an unbounded floating point color for averaging (summing then dividing) things. |
well, the Hue component in HSV/HSB comes to mind, for example, since it loops around, i.e. hue=1 is the same as hue=0. |
also, sometimes you want it to be the case that that subtracting BLUE from BLACK gives you YELLOW, because then you can wrap and loop and get all psychadelic on it. |
also RED minus YELLOW is some kind of GREEN, it's not BLACK. (@liasomething says 'of course it's not black! RED minus RED is black.') |
yellow (FFFF00) minus red (FF0000) is green (00FF00), not the other way round, no? yay, colour theory... |
if they're numbers, yes. but they're not numbers, they're colours; minus ought to really act as a difference operator here. although it mathematically makes sense that RED minus YELLOW is BLACK, we have to ask what makes sense in terms of colours, and i say the difference between FF0000 and FFFF00 is always 00FF00. |
red (255,0,0) - yellow (255,255,0) = green (0,255,0) ? it seems you're intending to 'lock saturation' and simply transform the hue i.e. something like (pseudo)
p.s. agree with bilderbuchi, only hue should be 'looped' (i.e. integer overflow makes sense) perhaps @DamianNZ usage could be facilitated, e.g.:
|
this should definitely be clamped to 0 - ie no wrapping. |
I think clamping should be on by default with the option to disable. |
@kylemcdonald - can I assign this to you? I feel like this is your (color)wheel-house |
yeah i can get this before 0.8.0, thanks @ofTheo |
@DamianNZ it sounds like you want "difference" to mean "absolute difference"? is that the right interpretation of (red - yellow = green)? that's a separate issue from the clamping, though -- clamping can't be a mode you enable/disable, but it could be something you pass as an argument to a function. but for now i will just change ofColor so clamping is always enabled. |
could you leave a note and/or document that HSV hue will not loop (contrary to what could be expected)? |
@bilderbuchi don't you think it makes sense for is it more reasonable to have everything be clamped, or only to keep things that can overflow/underflow from over/underflowing? |
I have to admit I don't understand what you're saying. :-)
to mean that ofColors will automatically, always, be clamped, in which case a separate method would be superfluous. |
sorry, i didn't explain clearly enough. there is a difference between clamping and over/underflow. integral colors (unsigned short, unsigned char) can't be clamped, and real colors (float) can't over/underflow. instead of saying "clamping is always enabled" i should have said "over/underflow is not allowed". edit: also, it looks like all the operations are already clamped, it just doesn't mean anything most of the time. |
so here's a first pass at what i'm thinking kylemcdonald@61da27e this just does the add and subtract operations. if anyone has ideas/insight that would be appreciated :) |
regarding (red - yellow) = green, that should be handled as a feature request if it is still desired, rather than a bug, since the current behavior of the subtraction operator is now mathematically correct, useful, and can not be implemented with an "absolute difference" operator (i think). |
works for me! + 1 to merge |
When using the ofColor subtraction operator, negative results are clamped to positive values instead of 0. Values are circulating between 0 and 255, which could be useful for hue in HSV but in most cases (R, G, B..) is not what I would expect.
The text was updated successfully, but these errors were encountered: