Skip to content

Commit 781c058

Browse files
committed
Restore consistency with old color distances
The goal ultimately is that `abs2(g::Gray) == abs2(RGB(g::Gray))`, but for this package this will be a breaking change. Consquently, for now let's measure distances in a manner consistent with older ColorVectorSpace releases.
1 parent 17bf0e7 commit 781c058

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/core.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ accum_type(::Type{C}) where {C<:Colorant} = base_colorant_type(C){accum_type(e
77
accum_type(val) = isa(val, Type) ? throw_accum_type(val) : convert(accum_type(typeof(val)), val)
88
throw_accum_type(T) = error("type $T not supported in `accum_type`")
99

10-
_abs2(c::MathTypes) = c c
10+
# TODO:
11+
# _abs2(c::MathTypes) = c ⋅ c
12+
_abs2(c::MathTypes) = mapreducec(v->float(v)^2, +, 0, c)
1113
_abs2(x) = abs2(x)
1214

1315
default_diff_fn(c1::CT1,c2::CT2) where {CT1<:Union{Colorant,Real}, CT2<:Union{Colorant,Real}} = sqrt(_abs2(c1-accum_type(c2)))

test/flood_fill.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ using Test
5656
# Colors
5757
path = download("https://github.com/JuliaImages/juliaimages.github.io/raw/source/docs/src/pkgs/segmentation/assets/flower.jpg")
5858
img = load(path)
59-
seg = flood(img, CartesianIndex(87,280); thresh=0.3)
59+
seg = flood(img, CartesianIndex(87,280); thresh=0.3*sqrt(3)) # TODO: eliminate the sqrt(3) when we transition to `abs2(c) = c ⋅ c`
6060
@test 0.2*length(seg) <= sum(seg) <= 0.25*length(seg)
6161
c = mean(img[seg])
6262
# N0f8 makes for easier approximate testing

0 commit comments

Comments
 (0)