Commit 6919292f by Vedrana KRIVOKUCA

Fix Hamming Distance module

parent 700025b3
Pipeline #13245 failed with stages
in 12 minutes 11 seconds
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
import bob.ip.base
import numpy
import scipy.signal
from import Algorithm
class HammingDistance (Algorithm):
"""Finger vein matching: hamming distance
def __init__(
# 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
ch = ch,
cw = cw,
multiple_model_scoring = None,
multiple_probe_scoring = None
) = ch = 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
h, w = R.shape
crop_R = R[,]
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 = 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*, s0:s0+w-2*])))
return score
# Calculates the Hamming distance (proportion of mismatching corresponding bits) between two binary vectors
import scipy.spatial.distance
algorithm =
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment