Open johnnychen94 opened 2 years ago
To apply more efficient binary dithering, simply call dither(img, alg)
on a grayscale image without providing a colorscheme.
To return a Matrix{Bool}
, you can use dither(Bool, img, alg)
:
function dither_bw(img)
alg = DitherPunk.FloydSteinberg()
img = Gray{N0f8}.(img)
return DitherPunk.dither(Bool, img, alg)
end
img = testimage("cameraman");
@btime dither_bw($img) # 2.793 ms (17 allocations: 1.50 MiB)
When providing a colorscheme, DitherPunk calls the internal function colordither
instead of much faster binarydither!
.
Performance comparison between DitherPunk and MATLAB on FloydSteinberg algorithm:
version | matlab(ms) | ditherpunk(ms) |
---|---|---|
gray - binary | 2.7405 | 1.794 |
gray - cmap | x | 446.576 |
RGB - binary | x | 7.864 |
RGB - cmap | 4.1374 | 441.121 |
testimage("cameraman")
testimage("peppers_color")
x
: not supportedjulia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: 12th Gen Intel(R) Core(TM) i9-12900K
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, goldmont)
vs MATLAB's
dither
functionIt indicates that DitherPunk can be faster. The massive allocation count looks like type instability to me.