using DitherPunk
using DitherPunk: srgb2linear
using Images

Gradient Gallery

On color spaces

A simple linear gradient works well to reveal the characteristic patterns of different dithering algorithms.

srbg, linear = gradient_image(100, 800);
mosaicview(srbg, linear)

The pixel intensities in the image srgb increase linearly from 0 to 1. The second image linear has been converted from sRGB to a linear representation, which more closely matches our human perception of brightness.

The helper function test_on_gradient takes a dithering algorithm and runs it on both the srgb and the linear image. It then shows a comparison of both inputs and outputs:

function test_on_gradient(alg)
    srgb, linear = gradient_image(100, 800)
    dither_srgb = dither(srgb, alg)
    dither_linear = dither(linear, alg)

    return mosaicview([srgb, dither_srgb, linear, dither_linear]; ncol=1)
end;

Most dithering algorithms in DitherPunk.jl provide an optional parameter to_linear, which converts the input image to a linear color space before applying the dithering. Select what looks best!

Threshold dithering

ConstantThreshold

test_on_gradient(ConstantThreshold())

WhiteNoiseThreshold

test_on_gradient(WhiteNoiseThreshold())
Example block output

Ordered dithering

Bayer matrices

bayer_dithering

test_on_gradient(Bayer())
Example block output

The order of the Bayer-matrix can be specified through the parameter level, which defaults to 1. Level 2

test_on_gradient(Bayer(2))
Example block output

Level 3

test_on_gradient(Bayer(3))
Example block output

Level 4

test_on_gradient(Bayer(4))
Example block output

Clustered / halftone dithering

The following methods have large characteristic patterns and are therefore better suited for large images.

ClusteredDots

test_on_gradient(ClusteredDots())
Example block output

CentralWhitePoint

test_on_gradient(CentralWhitePoint())
Example block output

BalancedCenteredPoint

test_on_gradient(BalancedCenteredPoint())
Example block output

Rhombus

test_on_gradient(Rhombus())
Example block output

ImageMagick methods

test_on_gradient(IM_checks())
Example block output
test_on_gradient(IM_h4x4a())
Example block output
test_on_gradient(IM_h6x6a())
Example block output
test_on_gradient(IM_h8x8a())
Example block output
test_on_gradient(IM_h4x4o())
Example block output
test_on_gradient(IM_h6x6o())
Example block output
test_on_gradient(IM_h8x8o())
Example block output
test_on_gradient(IM_c5x5())
Example block output
test_on_gradient(IM_c6x6())
Example block output
test_on_gradient(IM_c7x7())
Example block output

Error diffusion

Note

If you are a dithering expert, the following images might look unusual to you. This is because DitherPunk iterates over colums first due to Julia's column-first memory layout for arrays.

SimpleErrorDiffusion

test_on_gradient(SimpleErrorDiffusion())
Example block output

FloydSteinberg

test_on_gradient(FloydSteinberg())
Example block output

JarvisJudice

test_on_gradient(JarvisJudice())
Example block output

Stucki

test_on_gradient(Stucki())
Example block output

Burkes

test_on_gradient(Burkes())
Example block output

Sierra

test_on_gradient(Sierra())
Example block output

TwoRowSierra

test_on_gradient(TwoRowSierra())
Example block output

SierraLite

test_on_gradient(SierraLite())
Example block output

Fan93()

test_on_gradient(Fan93())
Example block output

ShiauFan()

test_on_gradient(ShiauFan())
Example block output

ShiauFan2()

test_on_gradient(ShiauFan2())
Example block output

Atkinson()

test_on_gradient(Atkinson())
Example block output

This page was generated using Literate.jl.