diff --git a/Project.toml b/Project.toml index 5acec63..3f336ca 100644 --- a/Project.toml +++ b/Project.toml @@ -4,16 +4,16 @@ authors = ["Adrian Hill"] version = "2.3.1" [deps] -ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" +ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e" IndirectArrays = "9b13fd28-a010-5f03-acff-a1bbcff69959" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Requires = "ae029012-a4dd-5104-9daa-d747884805df" [compat] +ImageBase = "0.1.3" Clustering = "0.14" ColorSchemes = "3" -ImageCore = "0.8.1, 0.9" IndirectArrays = "0.5, 1.0" OffsetArrays = "1" Requires = "1" diff --git a/src/DitherPunk.jl b/src/DitherPunk.jl index fb739b5..fb8d59a 100644 --- a/src/DitherPunk.jl +++ b/src/DitherPunk.jl @@ -1,8 +1,8 @@ module DitherPunk -using ImageCore -using ImageCore: NumberLike, Pixel, GenericImage, GenericGrayImage, MappedArrays -using ImageCore.Colors: DifferenceMetric +using ImageBase +using ImageBase.ImageCore: NumberLike, Pixel, GenericImage, GenericGrayImage, MappedArrays +using ImageBase.ImageCore.Colors: DifferenceMetric using Random using IndirectArrays using OffsetArrays diff --git a/src/clustering.jl b/src/clustering.jl index 93fe5bf..8c8fea7 100644 --- a/src/clustering.jl +++ b/src/clustering.jl @@ -7,6 +7,10 @@ function get_colorscheme( tol=Clustering._kmeans_default_tol, )::Vector{Lab} # Cluster in Lab color space + + # Clustering on the downsampled image already generates good enough colormap estimation + # This significantly reduces the algorithmic complexity. + img = _restrict_to(img, ncolors*100) data = reshape(channelview(Lab.(img)), 3, :) R = Clustering.kmeans(data, ncolors; maxiter=maxiter, tol=tol) @@ -14,6 +18,15 @@ function get_colorscheme( return [Lab(c...) for c in eachcol(R.centers)] end +function _restrict_to(img, n) + length(img) <= n && return img + out = restrict(img) + while length(out) > n + out = restrict(out) + end + return out +end + function _colordither( ::Type{T}, img, diff --git a/test/test_color.jl b/test/test_color.jl index 4fc866f..b90310f 100644 --- a/test/test_color.jl +++ b/test/test_color.jl @@ -1,7 +1,7 @@ using DitherPunk using DitherPunk: ColorNotImplementedError using IndirectArrays -using ImageCore +using ImageBase using ReferenceTests using TestImages diff --git a/test/test_fixed_color.jl b/test/test_fixed_color.jl index 7cc157f..8198491 100644 --- a/test/test_fixed_color.jl +++ b/test/test_fixed_color.jl @@ -1,5 +1,5 @@ using DitherPunk -using ImageCore +using ImageBase using ReferenceTests using TestImages diff --git a/test/test_gradient.jl b/test/test_gradient.jl index 061923a..5165aa5 100644 --- a/test/test_gradient.jl +++ b/test/test_gradient.jl @@ -2,8 +2,8 @@ using DitherPunk using DitherPunk: gradient_image using ReferenceTests -using ImageCore -using ImageCore: GenericGrayImage +using ImageBase +using ImageBase.ImageCore: GenericGrayImage using UnicodePlots w = 200 diff --git a/test/test_utils.jl b/test/test_utils.jl index c10c37b..4af2063 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -1,6 +1,6 @@ using DitherPunk using DitherPunk: srgb2linear, clamp_limits -using ImageCore +using ImageBase @test srgb2linear(true) == true @test srgb2linear(false) == false