-
Notifications
You must be signed in to change notification settings - Fork 22
Implement abs2
#172
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
Implement abs2
#172
Conversation
I cannot decide whether this definition of |
The unit test is disabled after 60 days of inactivity. I just updated the CI configuration in #173, and I'm going to close&reopen to trigger the test. |
Codecov Report
@@ Coverage Diff @@
## master #172 +/- ##
==========================================
- Coverage 85.99% 85.93% -0.07%
==========================================
Files 2 2
Lines 257 263 +6
==========================================
+ Hits 221 226 +5
- Misses 36 37 +1
Continue to review full report at Codecov.
|
To avoid confusion, this PR should be released under another breaking release v0.10 or v1.0; we need a long window to allow people update their codes. |
Thanks for the implementation, @timholy. I want to express my support for this implementation; it works for our purposes as well as the prior implementation did. |
Great! It should be far better in the following sense: julia> using ColorTypes, ColorVectorSpace
julia> g = Gray(0.8)
Gray{Float64}(0.8)
julia> rgb = convert(RGB, g)
RGB{Float64}(0.8,0.8,0.8)
julia> abs2(g) ≈ abs2(rgb)
true There was a 3x difference between these in the 0.8 series. |
I've thought about this a bit; I'm not at all opposed to making this part of v0.10 or v1.0; however, there's a sense where much of the change will have to come after we release this. The reason? In JuliaImages/ImageSegmentation.jl#72 (comment), how do we go about deprecating this? I think we have to have a warning on every invocation that uses the fallback |
Why do we need to deprecate it? For compatibility with old versions and other frameworks, we still want to have the inconsistent |
You were concerned that people would need a long time to adjust in #172 (comment). My point is that they cannot even begin adjusting until this gets merged. Because I know I wasn't very clear, let me try again:
|
More eagerly advising users to change the codes sounds good to me. I've seen many hard landings to CVS v0.9 (e.g., the most recent one is JuliaPlots/VisualRegressionTests.jl#34), if we had ever had these messages it would be easier to do the transition. |
OK, here's a pretty different approach that I think solves all problems: tim@diva:~/.julia/dev/ColorVectorSpace$ julia -q --project --depwarn=yes
julia> using ColorTypes, ColorVectorSpace
julia> g = Gray(0.8)
Gray{Float64}(0.8)
julia> abs2(g)
0.6400000000000001
julia> abs2(RGB(g))
┌ Warning: The return value of `abs2` will change to ensure that `abs2(g::Gray) ≈ abs2(RGB(g::Gray))`.
│ For `RGB` colors, this results in dividing the previous output by 3.
│
│ To avoid this warning, use `ColorVectorSpace.Future.abs2` instead of `abs2`; currently,
│ `abs2` returns the old value (for compatibility), and `ColorVectorSpace.Future.abs2` returns the new value.
│ When making this change, you may also need to adjust constants like color-difference thresholds
│ to compensate for the change in the returned value.
│
│ If you are getting this from `var`, use `varmult` instead.
│ caller = top-level scope at REPL[4]:1
└ @ Core REPL[4]:1
1.9200000000000004
julia> ColorVectorSpace.Future.abs2(RGB(g))
0.6400000000000001
help?> ColorVectorSpace.Future.abs2
ColorVectorSpace.Future.abs2(c)
Return a scalar "squared magnitude" for color types. For RGB and gray, this is just the mean-square channelwise intensity.
Compatibility note: this gives a different result from Base.abs2(c), but eventually Base.abs2 will switch to the definition used here. Using ColorVectorSpace.Future.abs2 thus future-proofs your code.
For more information about the transition, see ColorVectorSpace's README. The proposed transition schedule is in the README; for convenience, it's
The two marked with Personally, this feels like the right way to do it. I am kicking myself that I didn't think of this from the beginning. Now that we've had https://github.com/JuliaGraphics/ColorVectorSpace.jl#abs-and-abs2 out there for a while, we've "decoupled" users' usage of |
Barring concerns, I'm merging this today and tagging a new release. However, I'm happy to make changes (e.g., if people think we need an even longer deprecation period, I'm fine with that, although it will delay the 1.0 release). |
To smoothly transition between the old `abs2` return value and the new one (which differs by a factor of 3 for RGB), this introduces an internal module `ColorVectorSpace.Future` permitting users to transition immediately to the new behavior. `Base.abs2` will return the old value with a depwarn; users can switch immediately to `ColorVectorSpace.Future.abs2` to avoid it.
abs2
was removed in #131 out of concerns about mathematical consistency. This brings it back in a way that's now consistent, but I think with different numeric values than previously. Even though ColorVectorSpace 0.9 has not yet bubbled up to the top of the JuliaImages stack, it may be time to consider restoring it.Fixes #157.