Skip to content

Commit

Permalink
remove duplicate matches
Browse files Browse the repository at this point in the history
  • Loading branch information
tejus-gupta committed Jan 2, 2018
1 parent 2c4ae93 commit 9c50c36
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
1 change: 0 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ Distributions 0.12
FixedPointNumbers 0.3
Compat 0.17
FLANN
NearestNeighbors
Distances
1 change: 0 additions & 1 deletion src/ImageFeatures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module ImageFeatures
using Images, ColorTypes, FixedPointNumbers, Distributions
using Compat
using FLANN, Distances
using NearestNeighbors

include("core.jl")
include("const.jl")
Expand Down
50 changes: 27 additions & 23 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function match_keypoints(keypoints_1::Keypoints, keypoints_2::Keypoints, desc_1,
s_key = keypoints_1
l_key = keypoints_2
order = false

if length(desc_1) > length(desc_2)
smaller = desc_2
larger = desc_1
Expand All @@ -97,38 +98,41 @@ function match_keypoints(keypoints_1::Keypoints, keypoints_2::Keypoints, desc_1,

matches = Keypoints[]

ndims=length(larger[1])
n_large=length(larger)
n_small=length(smaller)

data=Matrix{Float64}(ndims, n_large);
for i in 1:ndims
for j in 1:n_large
data[i,j]=larger[j][i]?1:0
end
end

if is_windows() && Sys.WORD_SIZE==32
tree = KDTree(data, Cityblock())

for i in 1:n_small
idx, dist = NearestNeighbors.knn(tree, smaller[i], 1)
if dist[1]/ndims < threshold
id_min = idx[1]
hamming_distances = [hamming_distance(s, l) for s in smaller, l in larger]
for i in 1:length(smaller)
if any(hamming_distances[i, :] .< threshold)
id_min = indmin(hamming_distances[i, :])
push!(matches, order ? [l_key[id_min], s_key[i]] : [s_key[i], l_key[id_min]])
hamming_distances[:, id_min] = 1.0
end
end
end
else
tree = flann(data, FLANNParameters(), Cityblock())
ndims=length(larger[1])
n_large=length(larger)
n_small=length(smaller)
data=Matrix{Float64}(ndims, n_large);
for i in 1:ndims
for j in 1:n_large
data[i,j]=larger[j][i]?1:0
end
end

tree = flann(data, FLANNParameters(), Cityblock())
matched = zeros(Bool, n_large)
for i in 1:n_small
idx, dist = FLANN.knn(tree, Vector{Float64}(smaller[i]), 1)
if dist[1]/ndims < threshold
id_min = idx[1]
push!(matches, order ? [l_key[id_min], s_key[i]] : [s_key[i], l_key[id_min]])
idx = inrange(tree, Vector{Float64}(smaller[i]), 0.1)
for j in idx[1]
if !matched[j]
id_min = j
push!(matches, order ? [l_key[id_min], s_key[i]] : [s_key[i], l_key[id_min]])
matched[j] = true
break
end
end
end
end

matches
end

Expand Down

0 comments on commit 9c50c36

Please sign in to comment.