diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..8622e38 Binary files /dev/null and b/.DS_Store differ 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..fa1e124 100644 --- a/src/kernel.jl +++ b/src/kernel.jl @@ -509,6 +509,26 @@ moffat(α::Real, β::Real) = moffat(α, β, ceil(Int, (α*2*sqrt sum(x.^2) end +""" +butterworth(n,Wn,ls{tuple}) -> 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)) + nn = 2*n + @. 1/(1+(sqrt(2)-1)*(df(R)/Wn)^nn) +end + +butterworth(n::Real, Wn::Real, ls::Integer) = butterworth(n, Wn, (ls,ls)) + """ reflect(kernel) --> reflectedkernel 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