Skip to content

Commit

Permalink
deprecate Kernel.gabor
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 committed Nov 3, 2021
1 parent 1e3e2f3 commit 2dbafa6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 64 deletions.
62 changes: 2 additions & 60 deletions src/kernel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -427,66 +427,6 @@ function laplacian2d(alpha::Number=0)
return centered([lc lb lc; lb lm lb; lc lb lc])
end

"""
gabor(size_x,size_y,σ,θ,λ,γ,ψ) -> (k_real,k_complex)
Returns a 2 Dimensional Complex Gabor kernel contained in a tuple where
- `size_x`, `size_y` denote the size of the kernel
- `σ` denotes the standard deviation of the Gaussian envelope
- `θ` represents the orientation of the normal to the parallel stripes of a Gabor function
- `λ` represents the wavelength of the sinusoidal factor
- `γ` is the spatial aspect ratio, and specifies the ellipticity of the support of the Gabor function
- `ψ` is the phase offset
#Citation
N. Petkov and P. Kruizinga, “Computational models of visual neurons specialised in the detection of periodic and aperiodic oriented visual stimuli: bar and grating cells,” Biological Cybernetics, vol. 76, no. 2, pp. 83–96, Feb. 1997. doi.org/10.1007/s004220050323
"""
function gabor(size_x::Integer, size_y::Integer, σ::Real, θ::Real, λ::Real, γ::Real, ψ::Real)

σx = σ
σy = σ/γ
nstds = 3
c = cos(θ)
s = sin(θ)

validate_gabor(σ,λ,γ)

if(size_x > 0)
xmax = floor(Int64,size_x/2)
else
@warn "The input parameter size_x should be positive. Using size_x = 6 * σx + 1 (Default value)"
xmax = round(Int64,max(abs(nstds*σx*c),abs(nstds*σy*s),1))
end

if(size_y > 0)
ymax = floor(Int64,size_y/2)
else
@warn "The input parameter size_y should be positive. Using size_y = 6 * σy + 1 (Default value)"
ymax = round(Int64,max(abs(nstds*σx*s),abs(nstds*σy*c),1))
end

xmin = -xmax
ymin = -ymax

x = [j for i in xmin:xmax,j in ymin:ymax]
y = [i for i in xmin:xmax,j in ymin:ymax]
xr = x*c + y*s
yr = -x*s + y*c

kernel_real = (exp.(-0.5*(((xr.*xr)/σx^2) + ((yr.*yr)/σy^2))).*cos.(2*/λ)*xr .+ ψ))
kernel_imag = (exp.(-0.5*(((xr.*xr)/σx^2) + ((yr.*yr)/σy^2))).*sin.(2*/λ)*xr .+ ψ))

kernel = (kernel_real,kernel_imag)
return kernel
end

function validate_gabor::Real::Real::Real)
if !>0 && λ>0 && γ>0)
throw(ArgumentError("The parameters σ, λ and γ must be positive numbers."))
end
end

"""
moffat(α, β, ls) -> k
Expand Down Expand Up @@ -540,4 +480,6 @@ if Base.VERSION >= v"1.4.2" && ccall(:jl_generating_output, Cint, ()) == 1
end
end

include("kernel_deprecated.jl")

end
62 changes: 62 additions & 0 deletions src/kernel_deprecated.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Deprecated

"""
gabor(size_x,size_y,σ,θ,λ,γ,ψ) -> (k_real,k_complex)
Returns a 2 Dimensional Complex Gabor kernel contained in a tuple where
- `size_x`, `size_y` denote the size of the kernel
- `σ` denotes the standard deviation of the Gaussian envelope
- `θ` represents the orientation of the normal to the parallel stripes of a Gabor function
- `λ` represents the wavelength of the sinusoidal factor
- `γ` is the spatial aspect ratio, and specifies the ellipticity of the support of the Gabor function
- `ψ` is the phase offset
# Citation
N. Petkov and P. Kruizinga, “Computational models of visual neurons specialised in the detection of periodic and aperiodic oriented visual stimuli: bar and grating cells,” Biological Cybernetics, vol. 76, no. 2, pp. 83–96, Feb. 1997. doi.org/10.1007/s004220050323
"""
function gabor(size_x::Integer, size_y::Integer, σ::Real, θ::Real, λ::Real, γ::Real, ψ::Real)
Base.depwarn("use `Kernel.Gabor` instead.", :gabor)
σx = σ
σy = σ/γ
nstds = 3
c = cos(θ)
s = sin(θ)

validate_gabor(σ,λ,γ)

if(size_x > 0)
xmax = floor(Int64,size_x/2)
else
@warn "The input parameter size_x should be positive. Using size_x = 6 * σx + 1 (Default value)"
xmax = round(Int64,max(abs(nstds*σx*c),abs(nstds*σy*s),1))
end

if(size_y > 0)
ymax = floor(Int64,size_y/2)
else
@warn "The input parameter size_y should be positive. Using size_y = 6 * σy + 1 (Default value)"
ymax = round(Int64,max(abs(nstds*σx*s),abs(nstds*σy*c),1))
end

xmin = -xmax
ymin = -ymax

x = [j for i in xmin:xmax,j in ymin:ymax]
y = [i for i in xmin:xmax,j in ymin:ymax]
xr = x*c + y*s
yr = -x*s + y*c

kernel_real = (exp.(-0.5*(((xr.*xr)/σx^2) + ((yr.*yr)/σy^2))).*cos.(2*/λ)*xr .+ ψ))
kernel_imag = (exp.(-0.5*(((xr.*xr)/σx^2) + ((yr.*yr)/σy^2))).*sin.(2*/λ)*xr .+ ψ))

kernel = (kernel_real,kernel_imag)
return kernel
end

function validate_gabor::Real::Real::Real)
if !>0 && λ>0 && γ>0)
throw(ArgumentError("The parameters σ, λ and γ must be positive numbers."))
end
end
3 changes: 0 additions & 3 deletions test/gabor.jl → test/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using ImageFiltering, Test, Statistics

@testset "gabor" begin
σx = 8
σy = 12
size_x = 6*σx+1
size_y = 6*σy+1
γ = σx/σy
# zero size forces default kernel width, with warnings
@info "Four warnings are expected"
kernel = Kernel.gabor(0,0,σx,0,5,γ,0)
@test isequal(size(kernel[1]),(size_x,size_y))
kernel = Kernel.gabor(0,0,σx,π,5,γ,0)
Expand Down
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using ImageQualityIndexes
import StaticArrays
using Random
using FFTW
using Statistics

@testset "Project meta quality checks" begin
# Ambiguity test
Expand Down Expand Up @@ -44,7 +45,6 @@ include("gradient.jl")
include("mapwindow.jl")
include("extrema.jl")
include("basic.jl")
# include("gabor.jl")
include("gaborkernels.jl")
include("models.jl")

Expand Down Expand Up @@ -72,4 +72,7 @@ if CUDA_FUNCTIONAL
else
@warn "CUDA test: disabled"
end

@info "Beginning deprecation tests, warnings are expected"
include("deprecated.jl")
nothing

0 comments on commit 2dbafa6

Please sign in to comment.