Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.bio.vein
Commits
6919292f
Commit
6919292f
authored
Oct 18, 2017
by
Vedrana KRIVOKUCA
Browse files
Fix Hamming Distance module
parent
700025b3
Pipeline
#13245
failed with stages
in 12 minutes and 11 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
bob/bio/vein/algorithm/HammingDistance.py
View file @
6919292f
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
import
bob.ip.base
import
numpy
import
scipy.signal
from
bob.bio.base.algorithm
import
Algorithm
class
HammingDistance
(
Algorithm
):
"""Finger vein matching: hamming distance
"""
def
__init__
(
self
,
# some similarity functions might need a GaborWaveletTransform class, so we have to provide the parameters here as well...
ch
=
8
,
# Maximum search displacement in y-direction
cw
=
5
,
# Maximum search displacement in x-direction
):
# call base class constructor
Algorithm
.
__init__
(
self
,
ch
=
ch
,
cw
=
cw
,
multiple_model_scoring
=
None
,
multiple_probe_scoring
=
None
)
self
.
ch
=
ch
self
.
cw
=
cw
def
enroll
(
self
,
enroll_features
):
"""Enrolls the model by computing an average graph for each model"""
# return the generated model
return
numpy
.
vstack
(
enroll_features
)
def
score
(
self
,
model
,
probe
):
"""Computes the score of the probe and the model
Return score - Value between 0 and 0.5, larger value is better match
"""
I
=
probe
.
astype
(
numpy
.
float64
)
R
=
model
.
astype
(
numpy
.
float64
)
h
,
w
=
R
.
shape
crop_R
=
R
[
self
.
ch
:
h
-
self
.
ch
,
self
.
cw
:
w
-
self
.
cw
]
rotate_R
=
numpy
.
zeros
((
crop_R
.
shape
[
0
],
crop_R
.
shape
[
1
]))
bob
.
ip
.
base
.
rotate
(
crop_R
,
rotate_R
,
180
)
#FFT for scoring!
#Nm=bob.sp.ifft(bob.sp.fft(I)*bob.sp.fft(rotate_R))
Nm
=
scipy
.
signal
.
convolve2d
(
I
,
rotate_R
,
'valid'
);
t0
,
s0
=
numpy
.
unravel_index
(
Nm
.
argmax
(),
Nm
.
shape
)
Nmm
=
Nm
[
t0
,
s0
]
#Nmm = Nm.max()
#mi = numpy.argwhere(Nmm == Nm)
#t0, s0 = mi.flatten()[:2]
score
=
Nmm
/
(
sum
(
sum
(
crop_R
))
+
sum
(
sum
(
I
[
t0
:
t0
+
h
-
2
*
self
.
ch
,
s0
:
s0
+
w
-
2
*
self
.
cw
])))
return
score
# Calculates the Hamming distance (proportion of mismatching corresponding bits) between two binary vectors
import
bob.bio.base
import
scipy.spatial.distance
algorithm
=
bob
.
bio
.
base
.
algorithm
.
Distance
(
distance_function
=
scipy
.
spatial
.
distance
.
hamming
,
is_distance_function
=
False
# setting this to False ensures that Hamming distances are returned as positive values rather than negative
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment