Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
bob.bio.vein
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bob
bob.bio.vein
Commits
6919292f
Commit
6919292f
authored
Oct 18, 2017
by
Vedrana KRIVOKUCA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
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
Sidebyside
Showing
1 changed file
with
8 additions
and
62 deletions
+8
62
HammingDistance.py
bob/bio/vein/algorithm/HammingDistance.py
+8
62
No files found.
bob/bio/vein/algorithm/HammingDistance.py
View file @
6919292f
#!/usr/bin/env python
# vim: set fileencoding=utf8 :
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 ydirection
cw
=
5
,
# Maximum search displacement in xdirection
):
# 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