Skip to content

Instantly share code, notes, and snippets.

@fonsp
Created October 22, 2020 17:23
Show Gist options
  • Save fonsp/07511cb95853d3c7929c0cb201caff58 to your computer and use it in GitHub Desktop.
Save fonsp/07511cb95853d3c7929c0cb201caff58 to your computer and use it in GitHub Desktop.
### A Pluto.jl notebook ###
# v0.12.4
using Markdown
using InteractiveUtils
# ╔═╡ b7737d96-1488-11eb-0be7-2d3d96b5993d
begin
import Pkg
Pkg.activate(mktempdir())
Pkg.add([
"PlutoUI",
"Images",
"ImageMagick"
])
using PlutoUI
using Images
end
# ╔═╡ d6358820-1488-11eb-18f3-212f6b3b16bd
i = Images.load(download("https://fonsp.com/img/doggoSmall.jpg?raw=true"))
# ╔═╡ 0ad23e32-1489-11eb-34dd-b5f9587487f8
sphere = (center = [4,0,0], radius=1)
# ╔═╡ 0be4fefa-148a-11eb-0a57-01dd9eb70aeb
floor(Int, 3.123)
# ╔═╡ 77a1dbe4-1489-11eb-2533-9749def8cfe5
function extend(img, x, y)
xi = floor(Int, x)
yi = floor(Int, y)
w, h = size(img)
img[clamp(xi, 1, w), clamp(yi, 1, h)]
end
# ╔═╡ aecf9ba0-148a-11eb-0a11-b57dc2ab33cb
CartesianIndex(1,2) + CartesianIndex(1,2)
# ╔═╡ 3676d1e6-148a-11eb-27e8-4d3b412af762
function distorted(distortion::Function, img)
map(CartesianIndices(img)) do I
new_I = I.I .+ distortion(I.I...)
extend(img, new_I...)
end
end
# ╔═╡ 5e50e4d6-148a-11eb-2753-69d4fa7eecf3
CartesianIndices(i)
# ╔═╡ 4b86b524-148a-11eb-3023-75973a6ec453
distorted(i) do x, y
sin(x/10) * 50, sin(y / 10) * 0
end
# ╔═╡ Cell order:
# ╠═b7737d96-1488-11eb-0be7-2d3d96b5993d
# ╠═d6358820-1488-11eb-18f3-212f6b3b16bd
# ╠═0ad23e32-1489-11eb-34dd-b5f9587487f8
# ╠═0be4fefa-148a-11eb-0a57-01dd9eb70aeb
# ╠═77a1dbe4-1489-11eb-2533-9749def8cfe5
# ╠═aecf9ba0-148a-11eb-0a11-b57dc2ab33cb
# ╠═3676d1e6-148a-11eb-27e8-4d3b412af762
# ╠═5e50e4d6-148a-11eb-2753-69d4fa7eecf3
# ╠═4b86b524-148a-11eb-3023-75973a6ec453
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment