Skip to content

Commit 1ad5c7a

Browse files
committed
16 bit types for freak and brisk
1 parent 5a24081 commit 1ad5c7a

File tree

4 files changed

+36
-40
lines changed

4 files changed

+36
-40
lines changed

src/brisk.jl

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,20 @@ brisk_params = BRISK([pattern_scale = 1.0])
77
|----------|------|-------------|
88
| `pattern_scale` | `Float64` | Scaling factor for the sampling window |
99
"""
10-
type BRISK{S, T, O} <: Params
10+
type BRISK{S, T, O, OW} <: Params
1111
threshold::Float64
1212
octaves::Int
1313
pattern_scale::Float64
1414
pattern_table::Vector{Vector{S}}
15-
smoothing_table::Vector{T}
16-
orientation_weights::Vector{O}
15+
smoothing_table::Vector{Vector{T}}
16+
orientation_weights::Vector{OW}
1717
short_pairs::Vector{O}
1818
long_pairs::Vector{O}
1919
end
2020

21-
typealias OrientationPair Vector{Int}
22-
typealias SamplePair Vector{Float64}
23-
2421
function BRISK(; threshold::Float64 = 0.25, octaves::Int = 4, pattern_scale = 1.0)
2522
pattern_table, smoothing_table = _brisk_tables(pattern_scale)
26-
orientation_weights = OrientationPair[]
23+
orientation_weights = OrientationWeights[]
2724
short_pairs = OrientationPair[]
2825
long_pairs = OrientationPair[]
2926
dminsq = (brisk_dmin * pattern_scale) ^ 2
@@ -34,7 +31,7 @@ function BRISK(; threshold::Float64 = 0.25, octaves::Int = 4, pattern_scale = 1.
3431
norm = dy ^ 2 + dx ^ 2
3532
if norm > dminsq
3633
push!(long_pairs, OrientationPair([j, i]))
37-
push!(orientation_weights, OrientationPair([round(Int, dy * 4096 / norm), round(Int, dx * 4096 / norm)]))
34+
push!(orientation_weights, OrientationWeights([dy / norm, dx / norm]))
3835
elseif norm < dmaxsq
3936
push!(short_pairs, OrientationPair([j, i]))
4037
end
@@ -44,15 +41,15 @@ function BRISK(; threshold::Float64 = 0.25, octaves::Int = 4, pattern_scale = 1.
4441
end
4542

4643
function _brisk_orientation{T<:Gray}(int_img::AbstractArray{T, 2}, keypoint::Keypoint, pattern::Array{SamplePair},
47-
orientation_weights::Array{OrientationPair}, sigmas::Array{Float64}, long_pairs::Array{OrientationPair})
44+
orientation_weights::Array{OrientationWeights}, sigmas::Array{Float16}, long_pairs::Array{OrientationPair})
4845
direction_sum_y = 0.0
4946
direction_sum_x = 0.0
5047
for (i, o) in enumerate(long_pairs)
5148
offset_1 = pattern[o[1]]
5249
offset_2 = pattern[o[2]]
5350
intensity_diff = ImageFeatures._freak_mean_intensity(int_img, keypoint, offset_1, sigmas[o[1]]) - ImageFeatures._freak_mean_intensity(int_img, keypoint, offset_2, sigmas[o[2]])
54-
direction_sum_y += orientation_weights[i][1] * intensity_diff / 4096
55-
direction_sum_x += orientation_weights[i][2] * intensity_diff / 4096
51+
direction_sum_y += orientation_weights[i][1] * intensity_diff
52+
direction_sum_x += orientation_weights[i][2] * intensity_diff
5653
end
5754
angle = atan2(direction_sum_y, direction_sum_x)
5855
scaled_angle = ceil(Int, (angle + pi) * brisk_orientation_steps / (2 * pi))
@@ -61,11 +58,11 @@ end
6158

6259
function _brisk_tables(pattern_scale::Float64)
6360
pattern_table = Vector{SamplePair}[]
64-
smoothing_table = Vector{Float64}[]
61+
smoothing_table = Vector{Float16}[]
6562
for ori in 0:brisk_orientation_steps - 1
6663
theta = ori * 2 * pi / brisk_orientation_steps
6764
pattern = SamplePair[]
68-
sigmas = Float64[]
65+
sigmas = Float16[]
6966
for (i, n) in enumerate(brisk_num_circular_pattern)
7067
for circle_number in 0:n - 1
7168
angle = (circle_number * 2 * pi / n) + theta
@@ -86,11 +83,10 @@ function create_descriptor{T<:Gray}(img::AbstractArray{T, 2}, features::Array{Fe
8683
descriptors = BitArray{1}[]
8784
ret_features = Feature[]
8885
window_size = ceil(Int, (brisk_radii[end] + brisk_sigma[end]) * params.pattern_scale * 0.85) + 1
89-
tl_lim = CartesianIndex(-window_size, -window_size)
90-
br_lim = CartesianIndex(window_size, window_size)
86+
lim = CartesianIndex(window_size, window_size)
9187
for feature in features
9288
keypoint = Keypoint(feature)
93-
checkbounds(Bool, img, keypoint + tl_lim) && checkbounds(Bool, img, keypoint + br_lim) || continue
89+
checkbounds(Bool, img, keypoint - lim) && checkbounds(Bool, img, keypoint + lim) || continue
9490
orientation = _brisk_orientation(int_img, keypoint, params.pattern_table[1], params.orientation_weights, params.smoothing_table[1], params.long_pairs)
9591
sampled_intensities = T[]
9692
for (i, p) in enumerate(params.pattern_table[orientation])

src/core.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ end
6161

6262
Keypoints(features::Features) = map(f -> f.keypoint, features)
6363

64+
typealias OrientationPair Vector{Int16}
65+
typealias OrientationWeights Vector{Float16}
66+
typealias SamplePair Vector{Float16}
67+
6468
"""
6569
```
6670
distance = hamming_distance(desc_1, desc_2)

src/freak.jl

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,27 @@ freak_params = FREAK([pattern_scale = 22.0])
77
|----------|------|-------------|
88
| **pattern_scale** | Float64 | Scaling factor for the sampling window |
99
"""
10-
type FREAK{S, T, O} <: Params
10+
type FREAK{S, T, OW} <: Params
1111
pattern_scale::Float64
12-
pattern_table::Array{Array{S, 1}, 1}
13-
smoothing_table::Array{T, 1}
14-
orientation_weights::Array{O, 1}
12+
pattern_table::Vector{Vector{S}}
13+
smoothing_table::Vector{Vector{T}}
14+
orientation_weights::Vector{OW}
1515
end
1616

17-
typealias OrientationPair Vector{Int}
18-
typealias SamplePair Vector{Float64}
19-
2017
function FREAK(; pattern_scale::Float64 = 22.0)
2118
pattern_table, smoothing_table = _freak_tables(pattern_scale)
22-
orientation_weights = OrientationPair[]
19+
orientation_weights = OrientationWeights[]
2320
for o in freak_orientation_sampling_pattern
2421
offset_1 = pattern_table[1][o[1]]
2522
offset_2 = pattern_table[1][o[2]]
2623
dy, dx = offset_1 - offset_2
2724
norm = (dx ^ 2 + dy ^ 2)
28-
push!(orientation_weights, OrientationPair([round(Int, dy * 4096 / norm), round(Int, dx * 4096 / norm)]))
25+
push!(orientation_weights, OrientationWeights([dy / norm, dx / norm]))
2926
end
3027
FREAK(pattern_scale, pattern_table, smoothing_table, orientation_weights)
3128
end
3229

33-
function _freak_mean_intensity{T<:Gray}(int_img::AbstractArray{T, 2}, keypoint::Keypoint, offset::SamplePair, sigma::Float64)
30+
function _freak_mean_intensity{T<:Gray}(int_img::AbstractArray{T, 2}, keypoint::Keypoint, offset::SamplePair, sigma::Float16)
3431
y = keypoint[1] + offset[1]
3532
x = keypoint[2] + offset[2]
3633
if sigma < 0.5
@@ -45,15 +42,15 @@ function _freak_mean_intensity{T<:Gray}(int_img::AbstractArray{T, 2}, keypoint::
4542
end
4643

4744
function _freak_orientation{T<:Gray}(int_img::AbstractArray{T, 2}, keypoint::Keypoint, pattern::Array{SamplePair},
48-
orientation_weights::Array{OrientationPair}, sigmas::Array{Float64})
45+
orientation_weights::Array{OrientationWeights}, sigmas::Array{Float16})
4946
direction_sum_y = 0.0
5047
direction_sum_x = 0.0
5148
for (i, o) in enumerate(freak_orientation_sampling_pattern)
5249
offset_1 = pattern[o[1]]
5350
offset_2 = pattern[o[2]]
5451
intensity_diff = _freak_mean_intensity(int_img, keypoint, offset_1, sigmas[o[1]]) - _freak_mean_intensity(int_img, keypoint, offset_2, sigmas[o[2]])
55-
direction_sum_y += orientation_weights[i][1] * intensity_diff / 4096
56-
direction_sum_x += orientation_weights[i][2] * intensity_diff / 4096
52+
direction_sum_y += orientation_weights[i][1] * intensity_diff
53+
direction_sum_x += orientation_weights[i][2] * intensity_diff
5754
end
5855
angle = atan2(direction_sum_y, direction_sum_x)
5956
scaled_angle = ceil(Int, (angle + pi) * freak_orientation_steps / (2 * pi))
@@ -62,11 +59,11 @@ end
6259

6360
function _freak_tables(pattern_scale::Float64)
6461
pattern_table = Vector{SamplePair}[]
65-
smoothing_table = Vector{Float64}[]
62+
smoothing_table = Vector{Float16}[]
6663
for ori in 0:freak_orientation_steps - 1
6764
theta = ori * 2 * pi / freak_orientation_steps
6865
pattern = SamplePair[]
69-
sigmas = Float64[]
66+
sigmas = Float16[]
7067
for (i, n) in enumerate(freak_num_circular_pattern)
7168
for circle_number in 0:n - 1
7269
alt_offset = (pi / n) * ((i - 1) % 2)
@@ -88,10 +85,9 @@ function create_descriptor{T<:Gray}(img::AbstractArray{T, 2}, keypoints::Keypoin
8885
descriptors = BitArray{1}[]
8986
ret_keypoints = Keypoint[]
9087
window_size = ceil(Int, (freak_radii[1] + freak_sigma[1]) * params.pattern_scale) + 1
91-
tl_lim = CartesianIndex(-window_size, -window_size)
92-
br_lim = CartesianIndex(window_size, window_size)
88+
lim = CartesianIndex(window_size, window_size)
9389
for k in keypoints
94-
checkbounds(Bool, img, k + tl_lim) && checkbounds(Bool, img, k + br_lim) || continue
90+
checkbounds(Bool, img, k - lim) && checkbounds(Bool, img, k + lim) || continue
9591
orientation = _freak_orientation(int_img, k, params.pattern_table[1], params.orientation_weights, params.smoothing_table[1])
9692
sampled_intensities = T[]
9793
for (i, p) in enumerate(params.pattern_table[orientation])

test/runtests.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ function _reverserotate(p, angle, center)
4747
return CartesianIndex(floor(Int, sin_angle * (p[2] - center[2]) + cos_angle * (p[1] - center[1]) + center[1]), floor(Int, cos_angle * (p[2] - center[2]) - sin_angle * (p[1] - center[1]) + center[2]))
4848
end
4949

50-
include("core.jl")
51-
include("brief.jl")
52-
include("glcm.jl")
53-
include("lbp.jl")
54-
include("corner.jl")
55-
include("orb.jl")
50+
# include("core.jl")
51+
# include("brief.jl")
52+
# include("glcm.jl")
53+
# include("lbp.jl")
54+
# include("corner.jl")
55+
# include("orb.jl")
5656
include("freak.jl")
5757
include("brisk.jl")
5858

0 commit comments

Comments
 (0)