Skip to content
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

[DoNotMerge] Test de bfd #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/differences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,23 +373,26 @@ end
function _colordiff(a_xyz::XYZ{T}, b_xyz::XYZ{T}, m::DE_BFD) where T
F = typeof(0.5f0 * zero(T)) === Float32 ? Float32 : promote_type(Float64, T)

la = muladd(F(54.6), log10(a_xyz.y + F(1.5)), F(-9.6))
lb = muladd(F(54.6), log10(b_xyz.y + F(1.5)), F(-9.6))
l_bfd(y) = muladd(F(54.6), log10(y + F(1.5)), F(-9.6))
la, lb = l_bfd.((a_xyz.y, b_xyz.y))

@show fma(F(54.6), log10(a_xyz.y + F(1.5)), F(-9.6))
@show F(54.6) * log10(b_xyz.y + F(1.5)) + F(-9.6)

# Convert into Lab with the proper white point
wpf = XYZ{F}(m.wp)
a_lab = convert(Lab, a_xyz, wpf)
b_lab = convert(Lab, b_xyz, wpf)

# Substitute the different L values
a = Lab(la, a_lab.a, a_lab.b)
b = Lab(lb, b_lab.a, b_lab.b)
@show a = Lab(la, a_lab.a, a_lab.b)
@show b = Lab(lb, b_lab.a, b_lab.b)

# Calculate deltas in each direction
dl, dc, dh = b.l - a.l, delta_c(b, a), delta_h(b, a)
@show dl, dc, dh = b.l - a.l, delta_c(b, a), delta_h(b, a)

# Find the mean value of the inputs to use as the "standard"
mc, mh = (chroma(a) + chroma(b)) * F(0.5), mean_hue(a, b)
@show mc, mh = (chroma(a) + chroma(b)) * F(0.5), mean_hue(a, b)

# Correction terms for a variety of nonlinearities in CIELAB.
g = sqrt(mc^4 / (mc^4 + 14000))
Expand All @@ -409,9 +412,9 @@ function _colordiff(a_xyz::XYZ{T}, b_xyz::XYZ{T}, m::DE_BFD) where T
F( 0.226) * cosd(4mh + 140) +
F(-0.194) * cosd(5mh + 280)

dcc = muladd(F(0.035), mc / muladd(F(0.00365), mc, 1) , F(0.521))
dhh = dcc * muladd(g, t, 1 - g)
rt = rc * rh
@show dcc = muladd(F(0.035), mc / muladd(F(0.00365), mc, 1) , F(0.521))
@show dhh = dcc * muladd(g, t, 1 - g)
@show rt = rc * rh

# Final calculation
sqrt((dl/F(m.kl))^2 + (dc/(F(m.kc)*dcc))^2 + (dh/dhh)^2 + rt*((dc*dh)/(dcc*dhh)))
Expand Down
5 changes: 5 additions & 0 deletions test/colordiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ using Colors: _de2000_t, _de2000_rot
pairs = ((a, b) for a in colors for b in Iterators.filter(c -> c != a,colors))
tri = (colorant"navy", colorant"peru", colorant"gold")

for c in colors
@show colordiff(c, c; metric=DE_BFD())
end
#=
@testset "properties of metrics" begin
metrics = (DE_2000(), DE_94(), DE_JPC79(), DE_CMC(), DE_BFD(),
DE_AB(), DE_DIN99(), DE_DIN99d(), DE_DIN99o())
Expand Down Expand Up @@ -117,4 +121,5 @@ using Colors: _de2000_t, _de2000_rot
@test_throws ArgumentError colordiff(RGBA(1,0,0,0.5), RGB(1,0,0))
@test_throws ArgumentError colordiff(RGBA(1,0,0,0.5), RGBA(1,0,0,0.5))
end
=#
end
22 changes: 11 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Colors, Test
@test isempty(detect_ambiguities(Colors))
#@test isempty(detect_ambiguities(Colors))

include("algorithms.jl")
include("conversion.jl")
include("colormaps.jl")
include("colormatch.jl")
#include("algorithms.jl")
#include("conversion.jl")
#include("colormaps.jl")
#include("colormatch.jl")
include("colordiff.jl")
include("din99.jl")
include("display.jl")
include("parse.jl")
include("utilities.jl")
#include("din99.jl")
#include("display.jl")
#include("parse.jl")
#include("utilities.jl")

using AbstractTrees
@test isempty(detect_ambiguities(Colors))
#using AbstractTrees
#@test isempty(detect_ambiguities(Colors))
Loading