-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FloydSteinberg performance issue for given colormap #70
Comments
To apply more efficient binary dithering, simply call To return a 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 |
Performance comparison between DitherPunk and MATLAB on FloydSteinberg algorithm:
julia> 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) benchmark codes# DitherPunk.jl
using ImageCore, ImageShow, DitherPunk, TestImages
using Clustering
alg = FloydSteinberg()
img_gray = testimage("cameraman")
img_rgb = testimage("peppers_color")
# gray - binary
@btime dither($img_gray, $alg); # 1.794 ms (5 allocations: 1.25 MiB)
# gray - cmap
cmap = DitherPunk.get_colorscheme(img_gray, 8)
@btime dither($img_gray, $alg, $cmap); # 446.576 ms (30394703 allocations: 558.88 MiB)
# rgb - binary
@btime dither($img_rgb, $alg); # 7.864 ms (11 allocations: 3.75 MiB)
# rgb - cmap
cmap = DitherPunk.get_colorscheme(img_rgb, 8)
@btime dither($img_rgb, $alg, $cmap); # 441.121 ms (30093620 allocations: 554.28 MiB) % matlab
img_gray = im2double(imresize(imread("cameraman.tif"), [512, 512]));
img_rgb = im2double(imread("peppers_color.tif"));
% gray - binary
f = @() dither(img_gray);
timeit(f) * 1000 % 2.7405
% % gray - cmap
% [idx, cmap] = kmeans(img_gray(:), 8);
% dither(img_gray, cmap)
% % rgb - binary
% f = @() dither(img_rgb);
% timeit(f) * 1000 % 2.7405
% rgb - cmap
[idx, cmap] = kmeans(reshape(img_rgb, 512*512, 3), 8);
f = @() dither(img_rgb, cmap)
timeit(f) * 1000 % 4.1374 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
vs MATLAB's
dither
functionIt indicates that DitherPunk can be faster. The massive allocation count looks like type instability to me.
The text was updated successfully, but these errors were encountered: