Skip to content

Commit 22eae13

Browse files
committed
Adds Filter Stack for OctagonalFilter
1 parent 088648c commit 22eae13

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

src/censure.jl

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ abstract BiFilter
33
type BoxFilter <: BiFilter
44

55
filter :: Array{Float64, 2}
6-
m_out :: UInt8
7-
m_in :: UInt8
8-
9-
BoxFilter(mo, mi) = new(ones(Float64, mo, mo), mo, mi)
6+
scale :: UInt8
107

118
end
129

@@ -18,29 +15,33 @@ type OctagonFilter <: BiFilter
1815
n_out :: UInt8
1916
n_in :: UInt8
2017

21-
OctagonFilter(mo, mi, no, ni) = new(ones(Float64, mo + 2 * no, mo + 2 * no), mo, mi, no, ni)
22-
2318
end
2419

2520
type CENSURE <: Detector
2621

2722
smallest :: Integer
2823
largest :: Integer
29-
filter :: Type
24+
filter_type :: Type
25+
filter_stack :: Array{BiFilter}
3026
responseThreshold :: Number
3127
lineThreshold :: Number
3228

3329
end
3430

3531
function createFilter(OF::OctagonFilter)
32+
area_out = (OF.m_out + 2 * OF.n_out) ^ 2 - 2 * OF.n_out ^ 2
33+
area_in = (OF.m_in + 2 * OF.n_in) ^ 2 - 2 * OF.n_in ^ 2
34+
weight_out = 1.0/(area_out - area_in)
35+
weight_in = 1.0/area_in
36+
OF.filter[:, :] = weight_out
3637
inner_start = Int(0.5 * ((OF.m_out + 2 * OF.n_out) - (OF.m_in + 2 * OF.n_in)))
37-
OF.filter[inner_start + 1 : end - inner_start, inner_start + 1 : end - inner_start] = -1
38+
OF.filter[inner_start + 1 : end - inner_start, inner_start + 1 : end - inner_start] = weight_in
3839

3940
for i in 1:OF.n_in
40-
OF.filter[inner_start + i, inner_start + 1 : inner_start + OF.n_in - i + 1] = 0
41-
OF.filter[inner_start + i, inner_start + OF.n_in + OF.m_in + i : inner_start + OF.m_in + 2 * OF.n_in] = 0
42-
OF.filter[inner_start + OF.m_in + 2 * OF.n_in - i + 1, inner_start + 1 : inner_start + OF.n_in - i + 1] = 0
43-
OF.filter[inner_start + OF.m_in + 2 * OF.n_in - i + 1, inner_start + OF.n_in + OF.m_in + i : inner_start + OF.m_in + 2 * OF.n_in] = 0
41+
OF.filter[inner_start + i, inner_start + 1 : inner_start + OF.n_in - i + 1] = weight_out
42+
OF.filter[inner_start + i, inner_start + OF.n_in + OF.m_in + i : inner_start + OF.m_in + 2 * OF.n_in] = weight_out
43+
OF.filter[inner_start + OF.m_in + 2 * OF.n_in - i + 1, inner_start + 1 : inner_start + OF.n_in - i + 1] = weight_out
44+
OF.filter[inner_start + OF.m_in + 2 * OF.n_in - i + 1, inner_start + OF.n_in + OF.m_in + i : inner_start + OF.m_in + 2 * OF.n_in] = weight_out
4445
end
4546

4647
for i in 1:OF.n_out
@@ -53,13 +54,33 @@ function createFilter(OF::OctagonFilter)
5354
end
5455

5556
function createFilter(BF::BoxFilter)
56-
inner_start = Int(0.5 * (BF.m_out - BF.m_in))
57-
BF.filter[inner_start + 1 : end - inner_start, inner_start + 1 : end - inner_start] = -1
57+
5858
end
5959

60-
CENSURE(; smallest::Integer = 1, largest::Integer = 7, filter::Type = BoxFilter, responseThreshold::Number = 0.15, lineThreshold::Number = 10) = CENSURE(scale, filter, responseThreshold, lineThreshold)
60+
OctagonFilter(mo, mi, no, ni) = (OF = OctagonFilter(ones(Float64, mo + 2 * no, mo + 2 * no), mo, mi, no, ni); createFilter(OF); OF)
61+
BoxFilter(s) = (BF = BoxFilter(ones(Float64, 4 * s + 1, 4 * s + 1), s); createFilter(BF); BF)
6162

62-
function censure{T}(img::AbstractArray{T, 2}, params::CENSURE)
63+
OctagonFilter_Kernels = [
64+
[5, 3, 2, 0],
65+
[5, 3, 3, 1],
66+
[7, 3, 3, 2],
67+
[9, 5, 4, 2],
68+
[9, 5, 7, 3],
69+
[13, 5, 7, 4],
70+
[15, 5, 10, 5]
71+
]
6372

73+
BoxFilter_Kernels = [1, 2, 3, 4, 5, 6, 7]
6474

75+
Kernels = Dict(BoxFilter => BoxFilter_Kernels, OctagonFilter => OctagonFilter_Kernels)
76+
77+
function getFilterStack(filter_type::Type, smallest::Integer, largest::Integer)
78+
k = Kernels[filter_type]
79+
filter_stack = map(f -> filter_type(f...), k[smallest : largest])
80+
end
81+
82+
CENSURE(; smallest::Integer = 1, largest::Integer = 7, filter::Type = OctagonFilter, responseThreshold::Number = 0.15, lineThreshold::Number = 10) = CENSURE(smallest, largest, filter, getFilterStack(filter, smallest, largest), responseThreshold, lineThreshold)
83+
84+
function censure{T}(img::AbstractArray{T, 2}, params::CENSURE)
85+
6586
end

0 commit comments

Comments
 (0)