diff --git a/src/clustering.jl b/src/clustering.jl index 72aa853..2b2fc04 100644 --- a/src/clustering.jl +++ b/src/clustering.jl @@ -54,8 +54,9 @@ end function _kmeans(alg::KMeansQuantization, cs::AbstractArray{<:Colorant{T,N}}) where {T,N} data = reshape(channelview(cs), N, :) - R = kmeans( + result = kmeans( data, alg.ncolors; maxiter=alg.maxiter, tol=alg.tol, init=alg.init, rng=alg.rng ) - return colorview(eltype(cs), R.centers) + centers = convert.(T, result.centers) + return colorview(eltype(cs), centers) end diff --git a/test/Project.toml b/test/Project.toml index 7ecac07..8b59942 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,6 +1,7 @@ [deps] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" +FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" diff --git a/test/references/KMeansQuantization8_N0f8.txt b/test/references/KMeansQuantization8_N0f8.txt new file mode 100644 index 0000000..ca89253 --- /dev/null +++ b/test/references/KMeansQuantization8_N0f8.txt @@ -0,0 +1 @@ +████████ \ No newline at end of file diff --git a/test/references/KMeansQuantization8_N0f8_HSV.txt b/test/references/KMeansQuantization8_N0f8_HSV.txt new file mode 100644 index 0000000..42ca694 --- /dev/null +++ b/test/references/KMeansQuantization8_N0f8_HSV.txt @@ -0,0 +1 @@ +████████ \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 4ac5409..abd656a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,9 +1,9 @@ using ColorQuantization -using Test -using Aqua +using Test, Aqua using TestImages, ReferenceTests -using Colors using Random, StableRNGs +using Colors: RGB, HSV +using FixedPointNumbers: N0f8 # Run Aqua.jl quality assurance tests Aqua.test_all(ColorQuantization; ambiguities=false) @@ -14,10 +14,12 @@ rng = StableRNG(123) Random.seed!(rng, 34568) img = testimage("peppers") +img_N0f8 = convert.(RGB{N0f8}, img) algs_deterministic = Dict( "UniformQuantization4" => UniformQuantization(4), - "KMeansQuantization8" => KMeansQuantization(8; rng=rng), + "KMeansQuantization8" => KMeansQuantization(8; rng=rng), + "KMeansQuantization8_N0f8" => KMeansQuantization(RGB{N0f8}, 8; rng=rng), ) @testset "ColorQuantization.jl" begin