Skip to content

Commit 32027e9

Browse files
committed
Adds FilterResponse for BoxFilter, Slant Integral Images for OctagonFilter
1 parent 22eae13 commit 32027e9

File tree

1 file changed

+82
-11
lines changed

1 file changed

+82
-11
lines changed

src/censure.jl

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
abstract BiFilter
22

33
type BoxFilter <: BiFilter
4-
5-
filter :: Array{Float64, 2}
6-
scale :: UInt8
4+
5+
scale :: Integer
6+
in_length :: Integer
7+
out_length :: Integer
8+
in_area :: Float64
9+
out_area :: Float64
10+
in_weight :: Float64
11+
out_weight :: Float64
712

813
end
914

@@ -22,7 +27,7 @@ type CENSURE <: Detector
2227
smallest :: Integer
2328
largest :: Integer
2429
filter_type :: Type
25-
filter_stack :: Array{BiFilter}
30+
filter_stack :: Array
2631
responseThreshold :: Number
2732
lineThreshold :: Number
2833

@@ -53,12 +58,8 @@ function createFilter(OF::OctagonFilter)
5358

5459
end
5560

56-
function createFilter(BF::BoxFilter)
57-
58-
end
59-
6061
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)
62+
BoxFilter(s) = (BF = BoxFilter(s, 2 * s + 1, 4 * s + 1, (2 * s + 1) ^ 2, (4 * s + 1) ^ 2, 0.0, 0.0); BF.in_weight = 1.0 / BF.in_area; BF.out_weight = 1.0 / (BF.out_area - BF.in_area); BF; )
6263

6364
OctagonFilter_Kernels = [
6465
[5, 3, 2, 0],
@@ -79,8 +80,78 @@ function getFilterStack(filter_type::Type, smallest::Integer, largest::Integer)
7980
filter_stack = map(f -> filter_type(f...), k[smallest : largest])
8081
end
8182

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+
function filterResponse{T}(int_img::AbstractArray{T, 2}, filter::BoxFilter)
84+
margin = filter.scale * 2
85+
n = filter.scale
86+
img_shape = size(int_img)
87+
response = zeros(img_shape)
88+
R = CartesianRange(CartesianIndex((margin + 1, margin + 1)), CartesianIndex((img_shape[1] - margin, img_shape[2] - margin)))
89+
in_sum = 0.0
90+
out_sum = 0.0
91+
for I in R
92+
topleft = I + CartesianIndex(- n - 1, - n - 1)
93+
topright = I + CartesianIndex(n, - n - 1)
94+
bottomleft = I + CartesianIndex(- n - 1, n)
95+
bottomright = I + CartesianIndex(n, n)
96+
A = topleft >= CartesianIndex(1, 1) ? int_img[topleft] : 0.0
97+
B = topright >= CartesianIndex(1, 1) ? int_img[topright] : 0.0
98+
C = bottomleft >= CartesianIndex(1, 1) ? int_img[bottomleft] : 0.0
99+
D = bottomright >= CartesianIndex(1, 1) ? int_img[bottomright] : 0.0
100+
in_sum = A + D - B - C
101+
102+
topleft = I + CartesianIndex(- 2 * n - 1, - 2 * n - 1)
103+
topright = I + CartesianIndex(2 * n, - 2 * n - 1)
104+
bottomleft = I + CartesianIndex(- 2 * n - 1, 2 * n)
105+
bottomright = I + CartesianIndex(2 * n, 2 * n)
106+
A = topleft >= CartesianIndex(1, 1) ? int_img[topleft] : 0.0
107+
B = topright >= CartesianIndex(1, 1) ? int_img[topright] : 0.0
108+
C = bottomleft >= CartesianIndex(1, 1) ? int_img[bottomleft] : 0.0
109+
D = bottomright >= CartesianIndex(1, 1) ? int_img[bottomright] : 0.0
110+
out_sum = A + D - B - C - in_sum
111+
112+
response[I] = in_sum * filter.in_weight - out_sum * filer.out_weight
113+
end
114+
115+
response
116+
end
117+
118+
function filterResponse(int_imgs::Tuple, filter::OctagonFilter)
119+
int_img = int_imgs[1]
120+
rs_img = int_imgs[2]
121+
ls_img = int_imgs[3]
122+
end
123+
124+
getIntegralImage(img, filter_type::BoxFilter) = integral_image(img)
125+
126+
function getIntegralImage(img, filter_type::OctagonFilter)
127+
img_shape = size(img)
128+
int_img = zeros(img_shape)
129+
right_slant_img = zeros(img_shape)
130+
left_slant_img = zeros(img_shape)
131+
132+
int_img[1, :] = cumsum(img[1, :])
133+
right_slant_img[1, :] = int_img[1, :]
134+
left_slant_img[1, :] = int_img[1, :]
135+
136+
for i in 2:img_shape[1]
137+
sum = 0.0
138+
for j in 1:img_shape[2]
139+
sum += img[i, j]
140+
int_img[i, j] = sum + int_img[i - 1, j]
141+
left_slant_img[i, j] = sum
142+
right_slant_img[i, j] = sum
143+
144+
if j > 1 left_slant_img[i, j] += left_slant_img[i - 1, j - 1] end
145+
right_slant_img[i, j] += j < img_shape[2] ? right_slant_img[i - 1, j + 1] : right_slant_img[i - 1, j]
146+
end
147+
end
148+
int_img, right_slant_img, left_slant_img
149+
end
150+
151+
CENSURE(; smallest::Integer = 1, largest::Integer = 7, filter::Type = BoxFilter, responseThreshold::Number = 0.15, lineThreshold::Number = 10) = CENSURE(smallest, largest, filter, getFilterStack(filter, smallest, largest), responseThreshold, lineThreshold)
83152

84153
function censure{T}(img::AbstractArray{T, 2}, params::CENSURE)
85-
154+
int_img = getIntegralImage(img, params.filter_stack[1])
155+
responses = map(f -> filterResponse(int_img, f), params.filter_stack)
156+
responses
86157
end

0 commit comments

Comments
 (0)