Skip to content

Commit

Permalink
Allow any AbstractMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
adrhill committed Sep 14, 2024
1 parent f87dd79 commit 12c2819
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/ordered.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ When applying the algorithm to an image, the threshold matrix is repeatedly tile
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`.
"""
struct OrderedDither{I<:Integer,R<:Real} <: AbstractDither
mat::Matrix{I}
struct OrderedDither{I<:Integer,M<:AbstractMatrix{<:I},R<:Real} <: AbstractDither
mat::M
max::I
color_error_multiplier::R
end
function OrderedDither(
mat::AbstractMatrix{I};
max=convert(I, length(mat) + 1),
invert_map=false,
color_error_multiplier=0.5,
) where {I<:Integer}
if invert_map
mat_inv = max .- mat
return OrderedDither(mat_inv, max, color_error_multiplier)

function OrderedDither(
mat::M;
max::I=convert(I, length(mat) + 1),
invert_map=false,
color_error_multiplier::R=0.5,
) where {I<:Integer,M<:AbstractMatrix{<:I},R<:Real}
require_one_based_indexing(mat)
if invert_map
mat = max .- mat
end
return new{I,M,R}(mat, max, color_error_multiplier)
end
return OrderedDither(mat, max, color_error_multiplier)
end

function binarydither!(alg::OrderedDither, out::GenericGrayImage, img::GenericGrayImage)
Expand Down

0 comments on commit 12c2819

Please sign in to comment.