Skip to content

Commit 7f29c9e

Browse files
committed
deprecate Kernel.gabor
1 parent 48944e1 commit 7f29c9e

File tree

4 files changed

+68
-64
lines changed

4 files changed

+68
-64
lines changed

src/kernel.jl

+2-60
Original file line numberDiff line numberDiff line change
@@ -427,66 +427,6 @@ function laplacian2d(alpha::Number=0)
427427
return centered([lc lb lc; lb lm lb; lc lb lc])
428428
end
429429

430-
"""
431-
gabor(size_x,size_y,σ,θ,λ,γ,ψ) -> (k_real,k_complex)
432-
433-
Returns a 2 Dimensional Complex Gabor kernel contained in a tuple where
434-
435-
- `size_x`, `size_y` denote the size of the kernel
436-
- `σ` denotes the standard deviation of the Gaussian envelope
437-
- `θ` represents the orientation of the normal to the parallel stripes of a Gabor function
438-
- `λ` represents the wavelength of the sinusoidal factor
439-
- `γ` is the spatial aspect ratio, and specifies the ellipticity of the support of the Gabor function
440-
- `ψ` is the phase offset
441-
442-
#Citation
443-
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
444-
"""
445-
function gabor(size_x::Integer, size_y::Integer, σ::Real, θ::Real, λ::Real, γ::Real, ψ::Real)
446-
447-
σx = σ
448-
σy = σ/γ
449-
nstds = 3
450-
c = cos(θ)
451-
s = sin(θ)
452-
453-
validate_gabor(σ,λ,γ)
454-
455-
if(size_x > 0)
456-
xmax = floor(Int64,size_x/2)
457-
else
458-
@warn "The input parameter size_x should be positive. Using size_x = 6 * σx + 1 (Default value)"
459-
xmax = round(Int64,max(abs(nstds*σx*c),abs(nstds*σy*s),1))
460-
end
461-
462-
if(size_y > 0)
463-
ymax = floor(Int64,size_y/2)
464-
else
465-
@warn "The input parameter size_y should be positive. Using size_y = 6 * σy + 1 (Default value)"
466-
ymax = round(Int64,max(abs(nstds*σx*s),abs(nstds*σy*c),1))
467-
end
468-
469-
xmin = -xmax
470-
ymin = -ymax
471-
472-
x = [j for i in xmin:xmax,j in ymin:ymax]
473-
y = [i for i in xmin:xmax,j in ymin:ymax]
474-
xr = x*c + y*s
475-
yr = -x*s + y*c
476-
477-
kernel_real = (exp.(-0.5*(((xr.*xr)/σx^2) + ((yr.*yr)/σy^2))).*cos.(2*/λ)*xr .+ ψ))
478-
kernel_imag = (exp.(-0.5*(((xr.*xr)/σx^2) + ((yr.*yr)/σy^2))).*sin.(2*/λ)*xr .+ ψ))
479-
480-
kernel = (kernel_real,kernel_imag)
481-
return kernel
482-
end
483-
484-
function validate_gabor::Real::Real::Real)
485-
if !>0 && λ>0 && γ>0)
486-
throw(ArgumentError("The parameters σ, λ and γ must be positive numbers."))
487-
end
488-
end
489-
490430
"""
491431
moffat(α, β, ls) -> k
492432
@@ -540,4 +480,6 @@ if Base.VERSION >= v"1.4.2" && ccall(:jl_generating_output, Cint, ()) == 1
540480
end
541481
end
542482

483+
include("kernel_deprecated.jl")
484+
543485
end

src/kernel_deprecated.jl

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Deprecated
2+
3+
"""
4+
gabor(size_x,size_y,σ,θ,λ,γ,ψ) -> (k_real,k_complex)
5+
6+
Returns a 2 Dimensional Complex Gabor kernel contained in a tuple where
7+
8+
- `size_x`, `size_y` denote the size of the kernel
9+
- `σ` denotes the standard deviation of the Gaussian envelope
10+
- `θ` represents the orientation of the normal to the parallel stripes of a Gabor function
11+
- `λ` represents the wavelength of the sinusoidal factor
12+
- `γ` is the spatial aspect ratio, and specifies the ellipticity of the support of the Gabor function
13+
- `ψ` is the phase offset
14+
15+
# Citation
16+
17+
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
18+
"""
19+
function gabor(size_x::Integer, size_y::Integer, σ::Real, θ::Real, λ::Real, γ::Real, ψ::Real)
20+
Base.depwarn("use `Kernel.Gabor` instead.", :gabor)
21+
σx = σ
22+
σy = σ/γ
23+
nstds = 3
24+
c = cos(θ)
25+
s = sin(θ)
26+
27+
validate_gabor(σ,λ,γ)
28+
29+
if(size_x > 0)
30+
xmax = floor(Int64,size_x/2)
31+
else
32+
@warn "The input parameter size_x should be positive. Using size_x = 6 * σx + 1 (Default value)"
33+
xmax = round(Int64,max(abs(nstds*σx*c),abs(nstds*σy*s),1))
34+
end
35+
36+
if(size_y > 0)
37+
ymax = floor(Int64,size_y/2)
38+
else
39+
@warn "The input parameter size_y should be positive. Using size_y = 6 * σy + 1 (Default value)"
40+
ymax = round(Int64,max(abs(nstds*σx*s),abs(nstds*σy*c),1))
41+
end
42+
43+
xmin = -xmax
44+
ymin = -ymax
45+
46+
x = [j for i in xmin:xmax,j in ymin:ymax]
47+
y = [i for i in xmin:xmax,j in ymin:ymax]
48+
xr = x*c + y*s
49+
yr = -x*s + y*c
50+
51+
kernel_real = (exp.(-0.5*(((xr.*xr)/σx^2) + ((yr.*yr)/σy^2))).*cos.(2*/λ)*xr .+ ψ))
52+
kernel_imag = (exp.(-0.5*(((xr.*xr)/σx^2) + ((yr.*yr)/σy^2))).*sin.(2*/λ)*xr .+ ψ))
53+
54+
kernel = (kernel_real,kernel_imag)
55+
return kernel
56+
end
57+
58+
function validate_gabor::Real::Real::Real)
59+
if !>0 && λ>0 && γ>0)
60+
throw(ArgumentError("The parameters σ, λ and γ must be positive numbers."))
61+
end
62+
end

test/gabor.jl test/deprecated.jl

-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using ImageFiltering, Test, Statistics
2-
31
@testset "gabor" begin
42
σx = 8
53
σy = 12
64
size_x = 6*σx+1
75
size_y = 6*σy+1
86
γ = σx/σy
97
# zero size forces default kernel width, with warnings
10-
@info "Four warnings are expected"
118
kernel = Kernel.gabor(0,0,σx,0,5,γ,0)
129
@test isequal(size(kernel[1]),(size_x,size_y))
1310
kernel = Kernel.gabor(0,0,σx,π,5,γ,0)

test/runtests.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using ImageQualityIndexes
66
import StaticArrays
77
using Random
88
using FFTW
9+
using Statistics
910

1011
@testset "Project meta quality checks" begin
1112
# Ambiguity test
@@ -44,7 +45,6 @@ include("gradient.jl")
4445
include("mapwindow.jl")
4546
include("extrema.jl")
4647
include("basic.jl")
47-
# include("gabor.jl")
4848
include("gaborkernels.jl")
4949
include("models.jl")
5050

@@ -72,4 +72,7 @@ if CUDA_FUNCTIONAL
7272
else
7373
@warn "CUDA test: disabled"
7474
end
75+
76+
@info "Beginning deprecation tests, warnings are expected"
77+
include("deprecated.jl")
7578
nothing

0 commit comments

Comments
 (0)