Skip to content

Commit 0e51025

Browse files
gerrygraltonjohnnychen94
authored andcommitted
Add Moffat Kernel (#147)
* Add kernel using Moffat distribution * Add basic tests for moffat Kernel * Add docs for moffat Kernel to function_reference.md * Fix typo in docs * fixup! Add basic tests for moffat Kernel * Efficiency improvements
1 parent 7f0922d commit 0e51025

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

docs/src/function_reference.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Kernel.gaussian
2323
Kernel.DoG
2424
Kernel.LoG
2525
Kernel.Laplacian
26+
Kernel.moffat
2627
```
2728

2829
# KernelFactors

src/ImageFiltering.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ArrayLike{T} = Union{ArrayType{T}, AnyIIR{T}}
6464

6565
include("kernel.jl")
6666
using .Kernel
67-
using .Kernel: Laplacian, reflect, ando3, ando4, ando5, scharr, bickley, prewitt, sobel, gabor
67+
using .Kernel: Laplacian, reflect, ando3, ando4, ando5, scharr, bickley, prewitt, sobel, gabor, moffat
6868

6969
NDimKernel{N,K} = Union{AbstractArray{K,N},ReshapedOneD{K,N},Laplacian{N}}
7070

src/kernel.jl

+25
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,31 @@ function validate_gabor(σ::Real,λ::Real,γ::Real)
390390
end
391391
end
392392

393+
"""
394+
moffat(α, β, ls) -> k
395+
396+
Constructs a 2D, symmetric Moffat kernel `k` with core width, `α`, and power, `β`.
397+
Size of kernel defaults to 4 * full-width-half-max or as specified in `ls`.
398+
See [this notebook](https://nbviewer.jupyter.org/github/ysbach/AO_2017/blob/master/04_Ground_Based_Concept.ipynb#1.2.-Moffat) for details.
399+
400+
# Citation
401+
Moffat, A. F. J. "A theoretical investigation of focal stellar images in the photographic emulsion and application to photographic photometry." Astronomy and Astrophysics 3 (1969): 455.
402+
"""
403+
function moffat::Real, β::Real, ls::Tuple{Integer, Integer})
404+
ws = map(n->(ceil(Int,n)>>1), ls)
405+
R = CartesianIndices(map(w->IdentityUnitRange(-w:w), ws))
406+
α2 = α^2
407+
amp =- 1)/* α2)
408+
@. amp*((1+df(R)/α2)^-β)
409+
end
410+
moffat::Real, β::Real, ls::Integer) = moffat(α, β, (ls,ls))
411+
moffat::Real, β::Real) = moffat(α, β, ceil(Int, (α*2*sqrt(2^(1/β) - 1))*4))
412+
413+
@inline function df(I::CartesianIndex)
414+
x = SVector(Tuple(I))
415+
sum(x.^2)
416+
end
417+
393418
"""
394419
reflect(kernel) --> reflectedkernel
395420

test/specialty.jl

+9
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@ using ImageFiltering: IdentityUnitRange
216216
ImageFiltering.fillbuf_nan[] = false
217217
@test Kernel.LoG(2.5) == Kernel.LoG((2.5,2.5))
218218
end
219+
220+
@testset "moffat" begin
221+
α = rand()
222+
β = rand()
223+
@test Kernel.moffat(α,β,2) == Kernel.moffat(α,β,(2,2))
224+
225+
fwhm = ceil(Int, (α*2*sqrt(2^(1/β) - 1)) * 4)
226+
@test Kernel.moffat(α, β) == Kernel.moffat(α, β, (fwhm, fwhm))
227+
end
219228
end
220229

221230
nothing

0 commit comments

Comments
 (0)