-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
towards #17
- Loading branch information
Showing
1 changed file
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
### A Pluto.jl notebook ### | ||
# v0.14.8 | ||
|
||
using Markdown | ||
using InteractiveUtils | ||
|
||
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error). | ||
macro bind(def, element) | ||
quote | ||
local el = $(esc(element)) | ||
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : missing | ||
el | ||
end | ||
end | ||
|
||
# ╔═╡ af518646-d4e6-4779-bea7-d1297dfee472 | ||
begin | ||
using Pkg: Pkg | ||
Pkg.activate(mktempdir()) | ||
Pkg.add("PlutoUI") | ||
Pkg.add("Images") | ||
Pkg.add("ImageMagick") | ||
Pkg.add("DitherPunk") | ||
end | ||
|
||
# ╔═╡ 1bbc59ff-a98b-4e1f-a9bc-b9eed2dea33c | ||
begin | ||
using PlutoUI | ||
using Images | ||
using ImageMagick: load_ | ||
|
||
using DitherPunk | ||
end | ||
|
||
# ╔═╡ 6891dfb6-3fe5-4717-8237-a57bbf87d0cd | ||
md"# DitherPunk Demo" | ||
|
||
# ╔═╡ 51470fb2-ae78-11eb-3529-9599e47ad4c7 | ||
md""" | ||
## Load an image | ||
Welcome to the demo for our Julia package [DitherPunk.jl](https://github.com/adrhill/DitherPunk.jl)! | ||
Select a `png` or `jpg` file from your computer. It will automatically be converted to grayscale: | ||
""" | ||
|
||
# ╔═╡ 87476845-3892-411c-a958-d3fb786cd3ea | ||
@bind file FilePicker() | ||
|
||
# ╔═╡ cc480e47-d039-4741-967e-13b8c4c9c107 | ||
if isnothing(file) || isempty(file["data"]) | ||
md"""or paste your image URL here:""" | ||
else | ||
md"""Selected image $(file[\"name\"]).""" | ||
end | ||
|
||
# ╔═╡ 6369b9fa-726a-4b20-acdb-22bf4824eb51 | ||
if isnothing(file) || isempty(file["data"]) | ||
@bind url TextField(; default="https://testimages.juliaimages.org/images/cameraman.tif") | ||
end | ||
|
||
# ╔═╡ 7699f719-ab38-4e60-b7d4-a0652a5f5015 | ||
md"""## Select an algorithm""" | ||
|
||
# ╔═╡ a9d5c1bc-89b0-4f03-8108-cd16a201c876 | ||
@bind alg_name Select([ | ||
"Bayer level 1", | ||
"Bayer level 2", | ||
"Bayer level 3", | ||
"Bayer level 4", | ||
"Atkinson", | ||
"FloydSteinberg", | ||
"JarvisJudice", | ||
"Stucki", | ||
"Burkes", | ||
"Sierra", | ||
"TwoRowSierra", | ||
"SierraLite", | ||
"SimpleErrorDiffusion", | ||
"ClusteredDots", | ||
"CentralWhitePoint", | ||
"BalancedCenteredPoint", | ||
"Rhombus", | ||
"ConstantThreshold", | ||
"WhiteNoiseThreshold", | ||
]) | ||
|
||
# ╔═╡ 13f284f5-119a-41fd-b6a7-4cea4f1d1555 | ||
md"Image size: $(@bind width Slider(1:1000, default=256, show_value=true))" | ||
|
||
# ╔═╡ ee6e60b8-5a27-4d48-94e5-88cbd8a9522c | ||
md"Dither in linear colorspace: $(@bind to_linear CheckBox())" | ||
|
||
# ╔═╡ 59a30afb-6434-4fbc-85b6-241e8efb4171 | ||
md"""You can **right click** on your dithered image to save it. | ||
Feel free to [star our repo on GitHub](https://github.com/JuliaImages/DitherPunk.jl) and check out the [docs](https://juliaimages.org/DitherPunk.jl/stable/generated/color/) for color algorithms! | ||
""" | ||
|
||
# ╔═╡ cc3d95f9-ccda-465e-8dac-deaf622b7876 | ||
begin | ||
if isnothing(file) || isempty(file["data"]) | ||
img = load(download(url)) | ||
else | ||
img = load_(file["data"]) | ||
end | ||
ratio = width / maximum(size(img)) | ||
img = imresize(img; ratio=ratio) | ||
img = Gray.(img) | ||
end; | ||
|
||
# ╔═╡ 5c6d5500-6801-42a0-a338-ca57b8b15733 | ||
alg = Dict( | ||
"Atkinson" => Atkinson(), | ||
"FloydSteinberg" => FloydSteinberg(), | ||
"JarvisJudice" => JarvisJudice(), | ||
"Stucki" => Stucki(), | ||
"Burkes" => Burkes(), | ||
"Sierra" => Sierra(), | ||
"TwoRowSierra" => TwoRowSierra(), | ||
"SierraLite" => SierraLite(), | ||
"SimpleErrorDiffusion" => SimpleErrorDiffusion(), | ||
"Bayer level 1" => Bayer(), | ||
"Bayer level 2" => Bayer(; level=2), | ||
"Bayer level 3" => Bayer(; level=3), | ||
"Bayer level 4" => Bayer(; level=4), | ||
"ClusteredDots" => ClusteredDots(), | ||
"CentralWhitePoint" => CentralWhitePoint(), | ||
"BalancedCenteredPoint" => BalancedCenteredPoint(), | ||
"Rhombus" => Rhombus(), | ||
"ConstantThreshold" => ConstantThreshold(), | ||
"WhiteNoiseThreshold" => WhiteNoiseThreshold(), | ||
)[alg_name]; | ||
|
||
# ╔═╡ c62fa3a9-334e-4cc7-ae49-d6ab362c4a52 | ||
dither(img, alg; to_linear) | ||
|
||
# ╔═╡ Cell order: | ||
# ╟─6891dfb6-3fe5-4717-8237-a57bbf87d0cd | ||
# ╠═1bbc59ff-a98b-4e1f-a9bc-b9eed2dea33c | ||
# ╟─51470fb2-ae78-11eb-3529-9599e47ad4c7 | ||
# ╟─87476845-3892-411c-a958-d3fb786cd3ea | ||
# ╟─cc480e47-d039-4741-967e-13b8c4c9c107 | ||
# ╟─6369b9fa-726a-4b20-acdb-22bf4824eb51 | ||
# ╟─7699f719-ab38-4e60-b7d4-a0652a5f5015 | ||
# ╟─a9d5c1bc-89b0-4f03-8108-cd16a201c876 | ||
# ╟─13f284f5-119a-41fd-b6a7-4cea4f1d1555 | ||
# ╟─ee6e60b8-5a27-4d48-94e5-88cbd8a9522c | ||
# ╠═c62fa3a9-334e-4cc7-ae49-d6ab362c4a52 | ||
# ╟─59a30afb-6434-4fbc-85b6-241e8efb4171 | ||
# ╟─af518646-d4e6-4779-bea7-d1297dfee472 | ||
# ╟─cc3d95f9-ccda-465e-8dac-deaf622b7876 | ||
# ╟─5c6d5500-6801-42a0-a338-ca57b8b15733 |