Commit e04e8f9c authored by André Anjos's avatar André Anjos 💬

Fix save_data -> write_data changes; Updated docs

parent 654b700f
Pipeline #2866 passed with stage
in 4 minutes and 50 seconds
#!/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
gpu = False,
):
# 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
self.gpu = gpu
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))
if self.gpu == True:
import xbob.cusp
Nm = xbob.cusp.conv(I, rotate_R);
else:
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
......@@ -123,13 +123,3 @@ class LocalBinaryPatterns (Extractor):
finger_mask = image[1]
return self.lbp_features(finger_image, finger_mask)
def save_feature(self, feature, feature_file):
f = bob.io.base.HDF5File(feature_file, 'w')
f.set('feature', feature)
def read_feature(self, feature_file):
f = bob.io.base.HDF5File(feature_file, 'r')
image = f.read('feature')
return image
......@@ -267,13 +267,3 @@ class MaximumCurvature (Extractor):
finger_mask = image[1]
return self.maximum_curvature(finger_image, finger_mask)
def save_feature(self, feature, feature_file):
f = bob.io.base.HDF5File(feature_file, 'w')
f.set('feature', feature)
def read_feature(self, feature_file):
f = bob.io.base.HDF5File(feature_file, 'r')
image = f.read('feature')
return image
......@@ -32,14 +32,3 @@ class NormalisedCrossCorrelation (Extractor):
#TODO
return image_vein.astype(numpy.float64)
def save_feature(self, feature, feature_file):
f = bob.io.base.HDF5File(feature_file, 'w')
f.set('feature', feature)
def read_feature(self, feature_file):
f = bob.io.base.HDF5File(feature_file, 'r')
image = f.read('feature')
return (image)
......@@ -94,14 +94,3 @@ class PrincipalCurvature (Extractor):
finger_mask = image[1]
return self.principal_curvature(finger_image, finger_mask)
def save_feature(self, feature, feature_file):
f = bob.io.base.HDF5File(feature_file, 'w')
f.set('feature', feature)
def read_feature(self, feature_file):
f = bob.io.base.HDF5File(feature_file, 'r')
image = f.read('feature')
return (image)
......@@ -234,13 +234,3 @@ class RepeatedLineTracking (Extractor):
finger_mask = image[1]
return self.repeated_line_tracking(finger_image, finger_mask)
def save_feature(self, feature, feature_file):
f = bob.io.base.HDF5File(feature_file, 'w')
f.set('feature', feature)
def read_feature(self, feature_file):
f = bob.io.base.HDF5File(feature_file, 'r')
image = f.read('feature')
return (image)
......@@ -94,14 +94,3 @@ class WideLineDetector (Extractor):
finger_mask = image[1]
return self.wide_line_detector(finger_image, finger_mask)
def save_feature(self, feature, feature_file):
f = bob.io.base.HDF5File(feature_file, 'w')
f.set('feature', feature)
def read_feature(self, feature_file):
f = bob.io.base.HDF5File(feature_file, 'r')
image = f.read('feature')
return (image)
......@@ -6,6 +6,7 @@ import numpy
from PIL import Image
import bob.io.base
import bob.io.image
import bob.ip.base
import bob.sp
import bob.core
......@@ -505,7 +506,7 @@ class FingerCrop (Preprocessor):
return self.crop_finger(image)
def save_data(self, image, image_file):
def write_data(self, image, image_file):
f = bob.io.base.HDF5File(image_file, 'w')
f.set('image', image[0])
f.set('finger_mask', image[1])
......
......@@ -2,6 +2,8 @@
.. Mon 11 Jul 2016 16:39:15 CEST
.. _bob.bio.vein.api:
============
Python API
============
......
This diff is collapsed.
......@@ -18,3 +18,7 @@
.. _virtualbox: https://www.virtualbox.org
.. _hdf5: http://www.hdfgroup.org/HDF5
.. _bob.bio.base: https://pypi.python.org/pypi/bob.bio.base
.. _vera fingervein: https://www.idiap.ch/dataset/vera-fingervein
.. _vera palmvein: https://www.idiap.ch/dataset/vera-palmvein
.. _utfvp: http://scs.ewi.utwente.nl/downloads/show,Finger%20Vein/
.. _put: http://biometrics.put.poznan.pl/vein-dataset/
......@@ -20,3 +20,5 @@
.. [HDLTL10] *B. Huang, Y. Dai, R. Li, D. Tang and W. Li*, **Finger-vein authentication based on wide line detector and pattern normalization**, Proceedings on 20th International Conference on Pattern Recognition (ICPR), 2010.
.. [MD13] *L. Mirmohamadsadeghi and A. Drygajlo*, **Palm vein recognition using local texture patterns**, IET Biometrics, pp. 1-9, 2013.
.. [TVM14] *Pedro Tome, Matthias Vanoni and Sébastien Marcel*, **On the Vulnerability of Finger Vein Recognition to Spoofing**, in: IEEE International Conference of the Biometrics Special Interest Group (BIOSIG), Darmstadt, Germay, pages 1 - 10, IEEE, 2014
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 to comment