JuliaImages / DitherPunk.jl

Dithering algorithms in Julia.
MIT License
60 stars 3 forks source link

Some ordered dither threshold matrices are improperly treated #103

Open LukeTrainor opened 1 month ago

LukeTrainor commented 1 month ago

In ordered.jl the threshold matrix is converted into indices by mat = numerator.(alg.mat). If the denominator is not prime, however, the input threshold matrix will have some of its fractions simplified.

The simplest example I can find is IM_h4x4a(). The threshold matrix is

const H4X4A = [
    4 2 7 5
    3 1 8 6
    7 5 4 2
    8 6 3 1
]//9

but the result of numerator.(H4X4A) is

4×4 Matrix{Int64}:
 4  2  7  5
 1  1  8  2
 7  5  4  2
 8  2  1  1

A simple fix would be mat = numerator.(maximum(denominator.(alg.mat))*alg.mat), but there might be something more elegant.

adrhill commented 1 month ago

Nice catch, thanks a lot for reporting it!