From f00d04e805112bf490ab1945f750c60bd71e00d8 Mon Sep 17 00:00:00 2001 From: Ashwin V Date: Mon, 17 Jan 2022 15:27:35 +0530 Subject: [PATCH 1/5] add butterworth codes --- src/ImageFiltering.jl | 2 +- src/kernel.jl | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ImageFiltering.jl b/src/ImageFiltering.jl index 7f10bfe..70beb55 100644 --- a/src/ImageFiltering.jl +++ b/src/ImageFiltering.jl @@ -72,7 +72,7 @@ ArrayLike{T} = Union{ArrayType{T}, AnyIIR{T}} include("kernel.jl") using .Kernel -using .Kernel: Laplacian, reflect, ando3, ando4, ando5, scharr, bickley, prewitt, sobel, gabor, moffat +using .Kernel: Laplacian, reflect, ando3, ando4, ando5, scharr, bickley, prewitt, sobel, gabor, moffat, butterworth NDimKernel{N,K} = Union{AbstractArray{K,N},ReshapedOneD{K,N},Laplacian{N}} diff --git a/src/kernel.jl b/src/kernel.jl index 5d0993b..16c3522 100644 --- a/src/kernel.jl +++ b/src/kernel.jl @@ -509,6 +509,15 @@ moffat(α::Real, β::Real) = moffat(α, β, ceil(Int, (α*2*sqrt sum(x.^2) end +function butterworth(n::Real,Wn::Real,ls::Tuple{Integer, Integer}) + ws = map(n->(ceil(Int,n)>>1), ls) + R = CartesianIndices(map(w->IdentityUnitRange(-w:w), ws)) + nn = 2*n + @. 1/(1+(sqrt(2)-1)*(df(R)/Wn)^nn) +end + + + """ reflect(kernel) --> reflectedkernel From b6a98ca18a1277373fd71b9a995cfe20978590ec Mon Sep 17 00:00:00 2001 From: Ashwin V Date: Mon, 17 Jan 2022 15:29:12 +0530 Subject: [PATCH 2/5] add butterworth func --- src/kernel.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel.jl b/src/kernel.jl index 16c3522..4e746ce 100644 --- a/src/kernel.jl +++ b/src/kernel.jl @@ -516,7 +516,7 @@ function butterworth(n::Real,Wn::Real,ls::Tuple{Integer, Integer}) @. 1/(1+(sqrt(2)-1)*(df(R)/Wn)^nn) end - +butterworth(n::Real,Wn::Real,ls::Tuple{Integer, Integer}) = butterworth(n, Wn, (ls,ls)) """ reflect(kernel) --> reflectedkernel From 228207e58e3e9356b190a6d32ca8da7d4de9e908 Mon Sep 17 00:00:00 2001 From: Ashwin V <52974732+ashwinn-v@users.noreply.github.com> Date: Mon, 17 Jan 2022 20:01:49 +0530 Subject: [PATCH 3/5] Update src/kernel.jl Style fix Co-authored-by: Johnny Chen --- src/kernel.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel.jl b/src/kernel.jl index 4e746ce..678256b 100644 --- a/src/kernel.jl +++ b/src/kernel.jl @@ -509,7 +509,7 @@ moffat(α::Real, β::Real) = moffat(α, β, ceil(Int, (α*2*sqrt sum(x.^2) end -function butterworth(n::Real,Wn::Real,ls::Tuple{Integer, Integer}) +function butterworth(n::Real, Wn::Real, ls::Tuple{Integer,Integer}) ws = map(n->(ceil(Int,n)>>1), ls) R = CartesianIndices(map(w->IdentityUnitRange(-w:w), ws)) nn = 2*n From e10c1b0a0f3900a4a17e175ff65d3894d4ada1ea Mon Sep 17 00:00:00 2001 From: Ashwin V Date: Mon, 17 Jan 2022 21:18:26 +0530 Subject: [PATCH 4/5] minor changes --- src/kernel.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel.jl b/src/kernel.jl index 678256b..0608d47 100644 --- a/src/kernel.jl +++ b/src/kernel.jl @@ -516,7 +516,7 @@ function butterworth(n::Real, Wn::Real, ls::Tuple{Integer,Integer}) @. 1/(1+(sqrt(2)-1)*(df(R)/Wn)^nn) end -butterworth(n::Real,Wn::Real,ls::Tuple{Integer, Integer}) = butterworth(n, Wn, (ls,ls)) +butterworth(n::Real, Wn::Real, ls::Integer) = butterworth(n, Wn, (ls,ls)) """ reflect(kernel) --> reflectedkernel From a848ed02c3c124e2935ce5b16eb5c55fcdfe4a68 Mon Sep 17 00:00:00 2001 From: Ashwin V Date: Tue, 18 Jan 2022 00:12:26 +0530 Subject: [PATCH 5/5] Docs and Tests --- .DS_Store | Bin 0 -> 6148 bytes src/kernel.jl | 11 +++++++++++ test/specialty.jl | 8 ++++++++ 3 files changed, 19 insertions(+) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8622e38c9cf63abbfefdadf13e26f551c6453812 GIT binary patch literal 6148 zcmeHKOHRWu5FOKiqO$3drI#$&^aiF1C+G!G5=4;_Icmz@_vta%aVp--7?g@sVucWz zk?d#B#~#0`o|uT-=CxfDt%#^ZV{|;25mwKdF0%6#(8(H+dK&13I(nK}=r5``_a$=P zBjbi9`FGFjZ4>)JlfLBh%=-1Qs_HJ*u$OnYyJL8NyFc&S{@8ceP50;DhZZy<&!!!l zu8y$-7%&Em0b{@zIL81N5J-8gXuUCD3>X7n4DkKn(HKL$l@^t@UV+Xe{iP rcmTmzN- k +Returns a multidimensional dimensional Butterworth kernel contained in an OffsetArray(::Matrix{Float64}) + + - `n` is the order of the filter + - `Wn` is the normalized cutoff frequency + - `ls` is the size of the kernel +#Citation +Selesnick, Ivan W., and C. Sidney Burrus. "Generalized digital Butterworth filter design." IEEE Transactions on signal processing 46.6 (1998): 1688-1694. +""" + function butterworth(n::Real, Wn::Real, ls::Tuple{Integer,Integer}) ws = map(n->(ceil(Int,n)>>1), ls) R = CartesianIndices(map(w->IdentityUnitRange(-w:w), ws)) diff --git a/test/specialty.jl b/test/specialty.jl index 83a90bc..2dee4cc 100644 --- a/test/specialty.jl +++ b/test/specialty.jl @@ -238,6 +238,14 @@ using ImageFiltering: IdentityUnitRange fwhm = ceil(Int, (α*2*sqrt(2^(1/β) - 1)) * 4) @test Kernel.moffat(α, β) == Kernel.moffat(α, β, (fwhm, fwhm)) end + + @testset "butterworth" begin + a = rand() + b = rand() + @test Kernel.butterworth(a,b,(3,3)) == Kernel.butterworth(a,b,3) + @test Kernel.butterworth(a,b,(4,4)) == Kernel.butterworth(a,b,4) + end + end nothing