API Reference

DitherPunk.ditherFunction
dither([T::Type,] img, alg::AbstractDither, args...; kwargs...)

Dither image img using algorithm alg.

Output

If no return type is specified, dither will default to the type of the input image.

source
DitherPunk.dither!Function
dither!([out,] img, alg::AbstractDither, args...; kwargs...)

Dither image img using algorithm alg.

Output

If out is specified, it will be changed in place. Otherwise img will be changed in place.

source
DitherPunk.brailleFunction
braille(img; kwargs...)
braille(img, alg; kwargs...)

Binary dither with algorithm alg, then print image in braille.

Keyword arguments

  • invert: invert Unicode output, defaults to false
  • to_string: return a string instead of printing to terminal. Defaults to false.
  • method: method used to print in unicode. Either :braille or :block. Defaults to :braille.

All keyword arguments for binary dithering methods can be used.

source

Algorithm types

Error diffusion

DitherPunk.ErrorDiffusionType
ErrorDiffusion(filter, offset)

Generalized error diffusion algorithm. When calling dither using a color palette cs, this will iterate over pixels and round them to the closest color in cs. The rounding error is then "diffused" over the neighborhood defined by the matrix filter centered around an integer offset.

When using dither or dither! with an ErrorDiffusion method, the keyword argument clamp_error can be passed, which defaults to true. When true, the accumulated error on each pixel is clamped within limits of the image's colorant type before looking up the closest color. Setting clamp_error=false might be desired to achieve a glitchy effect.

Example

julia> alg = FloydSteinberg() # returns ErrorDiffusion instance
ErrorDiffusion{Rational{Int64}, UnitRange{Int64}}(CartesianIndex{2}[CartesianIndex(1, 0), CartesianIndex(-1, 1), CartesianIndex(0, 1), CartesianIndex(1, 1)], Rational{Int64}[7//16, 3//16, 5//16, 1//16], (-1:1, 0:1))

julia> cs = ColorSchemes.PuOr_7  # using ColorSchemes.jl for color palette presets

julia> dither(img, alg, cs)

julia> dither(img, alg, cs; clamp_error=false)
source
DitherPunk.FloydSteinbergFunction
FloydSteinberg()

Error diffusion algorithm using the filter

    *   7
3   5   1     (1//16)

References

[1] Floyd, R.W. and L. Steinberg, "An Adaptive Algorithm for Spatial Gray Scale." SID 1975, International Symposium Digest of Technical Papers, vol 1975m, pp. 36-37.

source
DitherPunk.JarvisJudiceFunction
JarvisJudice()

Error diffusion algorithm using the filter

        *   7   5
3   5   7   5   3
1   3   5   3   1   (1//48)

Also known as the Jarvis, Judice, and Ninke filter.

References

[1] Jarvis, J.F., C.N. Judice, and W.H. Ninke, "A Survey of Techniques for the Display of Continuous Tone Pictures on Bi-Level Displays," Computer Graphics and Image Processing, vol. 5, pp. 13-40, 1976.

source
DitherPunk.SierraFunction
Sierra()

Error diffusion algorithm using the filter

        *   5   3
2   4   5   4   2
    2   3   2       (1//32)

Also known as Sierra3 or three-row Sierra due to the filter shape.

source
DitherPunk.SierraLiteFunction
SierraLite()

Error diffusion algorithm using the filter

    *   2
1   1               (1//4)

Also known as Sierra-2-4A filter.

source
DitherPunk.StuckiFunction
Stucki()

Error diffusion algorithm using the filter

        *   8   4
2   4   8   4   2
1   2   4   2   1   (1//42)

References

[1] Stucki, P., "MECCA - a multiple-error correcting computation algorithm for bilevel image hardcopy reproduction." Research Report RZ1060, IBM Research Laboratory, Zurich, Switzerland, 1981.

source
DitherPunk.BurkesFunction
Burkes()

Error diffusion algorithm using the filter

        *   8   4
2   4   8   4   2
1   2   4   2   1   (1//42)

References

[1] Burkes, D., "Presentation of the Burkes error filter for use in preparing continuous-tone images for presentation on bi-level devices." Unpublished, 1988.

source
DitherPunk.Fan93Function
Fan93()

Error diffusion algorithm using the filter

      *  7
1  3  5            (1//16)

A modification of the weights used in the Floyd-Steinberg algorithm.

References

[1] Z. Fan, "A Simple Modification of Error Diffusion Weights", IS&T's 46th Annual Conference, May 9-14, 1993, Final Program and Advanced Printing of Paper Summaries, pp 113-115 (1993).

source
DitherPunk.ShiauFanFunction
ShiauFan()

Error diffusion algorithm using the filter

        *   4
1   1   2           (1//8)

References

[1] J. N. Shiau and Z. Fan. "Method for quantization gray level pixel data with extended distribution set", US 5353127A, United States Patent and Trademark Office, Oct. 4, 1993

source
DitherPunk.ShiauFan2Function
ShiauFan2()

Error diffusion algorithm using the filter

            *   8
1   1   2   4       (1//16)

References

[1] J. N. Shiau and Z. Fan. "Method for quantization gray level pixel data with extended distribution set", US 5353127A, United States Patent and Trademark Office, Oct. 4, 1993 [2] J. N. Shiau and Z. Fan. "A set of easily implementable coefficients in error-diffusion with reduced worm artifacts" Color Imaging: Device-Independent Color, Color Hard Copy, and Graphics Arts, volume 2658, pages 222–225. SPIE, March 1996.

source
DitherPunk.SimpleErrorDiffusionFunction
SimpleErrorDiffusion()

Error diffusion algorithm using the filter

*   1
1   0         (1//2)

References

[1] Floyd, R.W. and L. Steinberg, "An Adaptive Algorithm for Spatial Gray Scale." SID 1975, International Symposium Digest of Technical Papers, vol 1975m, pp. 36-37.

source

Ordered dithering

DitherPunk.OrderedDitherType
OrderedDither(mat::AbstractMatrix)

Generalized ordered dithering algorithm using a threshold map. Takes a normalized threshold matrix mat.

When applying the algorithm to an image, the threshold matrix is repeatedly tiled to match the size of the image. It is then applied as a per-pixel threshold map. Optionally, this final threshold map can be inverted by selecting invert_map=true.

source

Bayer

DitherPunk.BayerFunction
Bayer([level=1]; kwargs...)

Ordered dithering using the Bayer matrix as a threshold matrix. The Bayer matrix is of dimension $2^{n+1} \times 2^{n+1}$, where $n$ is the level, which defaults to 1.

[1] Bayer, B.E., "An Optimum Method for Two-Level Rendition of Continuous Tone Pictures," IEEE International Conference on Communications, Conference Records, 1973, pp. 26-11 to 26-15.

source

Halftoning

DitherPunk.RhombusFunction
Rhombus()

Diagonal ordered matrix with balanced centered points. Uses $8 \times 8$ threshold matrix RHOMBUS_MAT.

source

Threshold methods

DitherPunk.ClosestColorType

Simplest form of image quantization by turning each pixel to the closest one in the provided color palette cs. Technically this not a dithering algorithm as the quatization error is not "randomized".

source

Other

Utilities

Index