# HG changeset patch # User Tuomo Valkonen # Date 1576344393 -7200 # Node ID 0d99f8f7d26160824b08e42abb8a2960f73a9b03 # Parent 8ff7da7bc77dc4d7fa1c62c34afe0590d2cc6779 Added ImFilter & simple_imfilter. diff -r 8ff7da7bc77d -r 0d99f8f7d261 Manifest.toml --- a/Manifest.toml Sat Dec 14 14:59:59 2019 +0200 +++ b/Manifest.toml Sat Dec 14 19:26:33 2019 +0200 @@ -85,6 +85,11 @@ [[Mmap]] uuid = "a63ad114-7e13-5084-954f-fe012c677804" +[[OffsetArrays]] +git-tree-sha1 = "27f32af4e7b11f5aa9f3cad60b777cd042af149a" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "0.11.3" + [[OrderedCollections]] deps = ["Random", "Serialization", "Test"] git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1" diff -r 8ff7da7bc77d -r 0d99f8f7d261 Project.toml --- a/Project.toml Sat Dec 14 14:59:59 2019 +0200 +++ b/Project.toml Sat Dec 14 19:26:33 2019 +0200 @@ -8,5 +8,6 @@ ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" +OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" diff -r 8ff7da7bc77d -r 0d99f8f7d261 src/ImFilter.jl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ImFilter.jl Sat Dec 14 19:26:33 2019 +0200 @@ -0,0 +1,58 @@ +################################################## +# Simple (and fast for small filters compared to +# ImageFiltering) image filtering +################################################## + +__precompile__() + +module ImFilter + +using OffsetArrays + +########## +# Exports +########## + +export simple_imfilter + +############## +# The routine +############## + +@inline function inside(i, aʹ, bʹ, a, b) + return (max(a, i - aʹ) - i):(min(b, i + bʹ) - i) +end + +function simple_imfilter(b::Array{Float64,2}, + kernel::OffsetArray{Float64,2,Array{Float64,2}}) + + n, m = size(b) + k, 𝓁 = size(kernel) + o₁, o₂ = kernel.offsets + a₁, a₂ = k + o₁, 𝓁 + o₂ + b₁, b₂ = -1 - o₁, -1 - o₂ + kp = kernel.parent + + @assert(isodd(k) && isodd(𝓁)) + + res = similar(b) + + Threads.@threads for i=1:n + for j=1:m + tmp = 0.0 + it₁ = inside(i, a₁, b₁, 1, n) + it₂ = inside(j, a₂, b₂, 1, m) + for p=it₁ + @simd for q=it₂ + tmp += @inbounds(kp[p-o₁, q-o₂]*b[i+p,j+q]) + end + end + res[i, j] = tmp + end + end + + return res +end + +end # Module + diff -r 8ff7da7bc77d -r 0d99f8f7d261 src/ImageTools.jl --- a/src/ImageTools.jl Sat Dec 14 14:59:59 2019 +0200 +++ b/src/ImageTools.jl Sat Dec 14 19:26:33 2019 +0200 @@ -8,6 +8,7 @@ include("Translate.jl") include("Denoise.jl") include("Visualise.jl") +include("ImFilter.jl") end # module