Skip to content

Commit

Permalink
Revert default metric to DE_2000 (#92)
Browse files Browse the repository at this point in the history
* Revert default metric to `DE_2000`

* Update references

* Update docs
  • Loading branch information
adrhill authored Aug 22, 2022
1 parent 5dd3e68 commit a0c73c5
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 137 deletions.
30 changes: 15 additions & 15 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,12 @@ rubiks_colors = [white, yellow, green, orange, red, blue]

Currently, dithering in custom colors is limited to [`ErrorDiffusion`](@ref) and [`OrderedDither`](@ref) algorithms:
````@example simple_example
dither(img, rubiks_colors)
````

This result doesn't look too good since the default metric `DE_AB()` just uses Euclidean distances in `Lab` color space.
Playing around with [perceptual color difference metrics from Colors.jl](https://juliagraphics.github.io/Colors.jl/stable/colordifferences/) can help:
````@example simple_example
using Colors
dither(img, rubiks_colors; metric=DE_2000())
d = dither(img, rubiks_colors)
````

This looks much better than simply quantizing to the closest color:
````@example simple_example
dither(img, ClosestColor(), rubiks_colors; metric=DE_2000())
````

An interesting effect can also be achieved by color dithering gray-scale images:
````@example simple_example
d = dither(img_gray, rubiks_colors; metric=DE_2000())
dither(img, ClosestColor(), rubiks_colors)
````

The output from a color dithering algorithm is an [`IndirectArray`](https://github.com/JuliaArrays/IndirectArrays.jl), which contains a color palette
Expand All @@ -137,6 +125,18 @@ d.index
````
This `index` Matrix can be used in creative ways. Take a look at [ASCII dithering](@ref) for an example!

An interesting effect can also be achieved by color dithering gray-scale images:
````@example simple_example
dither(img_gray, rubiks_colors)
````

You can also play around with [perceptual color difference metrics from Colors.jl](https://juliagraphics.github.io/Colors.jl/stable/colordifferences/).
For faster dithering, the metric `DE_AB()` can be used, which computes Euclidean distances in `Lab` color space:
````@example simple_example
using Colors
dither(img, rubiks_colors; metric=DE_AB())
````

### ColorSchemes.jl
Predefined color schemes from [ColorSchemes.jl](https://juliagraphics.github.io/ColorSchemes.jl/stable/catalogue/) can also be used.
````@example simple_example
Expand All @@ -145,7 +145,7 @@ dither(img, ColorSchemes.PuOr_7)
````

````@example simple_example
dither(img, Bayer(), ColorSchemes.berlin; metric=DE_2000())
dither(img, Bayer(), ColorSchemes.berlin)
````

!!! note "Discover new color schemes"
Expand Down
2 changes: 1 addition & 1 deletion src/DitherPunk.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module DitherPunk

using ImageBase.ImageCore.ColorTypes
using ImageBase.ImageCore.Colors: DifferenceMetric, colordiff, DE_AB, invert_srgb_compand
using ImageBase.ImageCore.Colors: DifferenceMetric, colordiff, DE_2000, invert_srgb_compand
using ImageBase.ImageCore: channelview, floattype, clamp01
using ImageBase: restrict
using Base: require_one_based_indexing
Expand Down
6 changes: 4 additions & 2 deletions src/api/color.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function Base.showerror(io::IO, e::ColorNotImplementedError)
end
colordither(alg, img, cs, metric) = throw(ColorNotImplementedError(alg))

const DEFAULT_METRIC = DE_2000()

##############
# Public API #
##############
Expand Down Expand Up @@ -54,7 +56,7 @@ function _colordither(
img::GenericImage,
alg::AbstractDither,
cs::AbstractVector{<:Pixel};
metric::DifferenceMetric=DE_AB(),
metric::DifferenceMetric=DEFAULT_METRIC,
to_linear=false,
kwargs...,
) where {T}
Expand All @@ -74,7 +76,7 @@ function _colordither(
img::GenericImage,
alg::AbstractDither,
cs::AbstractVector{<:Color{<:Any,3}};
metric::DifferenceMetric=DE_AB(),
metric::DifferenceMetric=DEFAULT_METRIC,
to_linear=false,
kwargs...,
) where {T<:NumberLike}
Expand Down
34 changes: 17 additions & 17 deletions test/references/color/Bayer.txt

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions test/references/color/Bayer_from_gray.txt

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions test/references/color/ClosestColor.txt

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions test/references/color/ClosestColor_from_gray.txt

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions test/references/color/FloydSteinberg.txt

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions test/references/color/FloydSteinberg_clamp_error.txt

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions test/references/color/FloydSteinberg_from_gray.txt

Large diffs are not rendered by default.

0 comments on commit a0c73c5

Please sign in to comment.