Commit 331df584 authored by André Anjos's avatar André Anjos 💬

[extractors] Porting and cleanup

parent ebc2f696
#!/usr/bin/env python
# Pedro Tome <Pedro.Tome@idiap.ch>
import configurations
import tools
import preprocessing
import features
import tests
import script
#import utils
# vim: set fileencoding=utf-8 :
def get_config():
"""Returns a string containing the configuration information.
"""
import pkg_resources
packages = pkg_resources.require(__name__)
this = packages[0]
deps = packages[1:]
retval = "%s: %s (%s)\n" % (this.key, this.version, this.location)
retval += " - python dependencies:\n"
for d in deps: retval += " - %s: %s (%s)\n" % (d.key, d.version, d.location)
return retval.strip()
import bob.extension
return bob.extension.get_config(__name__)
# gets sphinx autodoc done right - don't remove it
__all__ = [_ for _ in dir() if not _.startswith('_')]
......@@ -5,18 +5,14 @@
import bob.ip.base
import bob.io.base
import numpy
import math
#from math import pi
#from mumpy import sqrt
import scipy.signal
from facereclib.features.Extractor import Extractor
from .. import utils
#from facereclib.utils import histogram
from bob.bio.base.features.Extractor import Extractor
class LocalBinaryPatterns (Extractor):
"""LBP feature extractor
"""LBP feature extractor, paramters fixed based on
L. Mirmohamadsadeghi and A. Drygajlo. Palm vein recognition uisng local texture patterns, IET Biometrics, pp. 1-9, 2013.
Parameters fixed based on L. Mirmohamadsadeghi and A. Drygajlo. Palm vein
recognition uisng local texture patterns, IET Biometrics, pp. 1-9, 2013.
"""
def __init__(
......@@ -34,8 +30,7 @@ class LocalBinaryPatterns (Extractor):
lbp_add_average = False,
# histogram options
sparse_histogram = False,
split_histogram = None
split_histogram = None,
):
# call base class constructor
......@@ -53,7 +48,7 @@ class LocalBinaryPatterns (Extractor):
lbp_compare_to_average = lbp_compare_to_average,
lbp_add_average = lbp_add_average,
sparse_histogram = sparse_histogram,
split_histogram = split_histogram
split_histogram = split_histogram,
)
# block parameters
......@@ -70,18 +65,19 @@ class LocalBinaryPatterns (Extractor):
add_average_bit = lbp_add_average,
uniform = lbp_uniform,
rotation_invariant = lbp_rotation_invariant,
border_handling = 'wrap'
border_handling = 'wrap',
)
self.m_split = split_histogram
self.m_sparse = sparse_histogram
if self.m_sparse and self.m_split:
raise ValueError("Sparse histograms cannot be split! Check your setup!")
raise ValueError("Sparse histograms cannot be split! Check your setup.")
def __fill__(self, lbphs_array, lbphs_blocks, j):
"""Copies the given array into the given blocks"""
# fill array in the desired shape
#For debugging
#import ipdb; ipdb.set_trace()
......@@ -90,7 +86,8 @@ class LocalBinaryPatterns (Extractor):
def lbp_features(self, finger_image, mask):
"""Computes and returns the LBP features for the given input fingervein image"""
"""Computes and returns the LBP features for the given input fingervein
image"""
# For debugging
#import ipdb; ipdb.set_trace()
......@@ -142,4 +139,4 @@ class LocalBinaryPatterns (Extractor):
def read_feature(self, feature_file):
f = bob.io.base.HDF5File(feature_file, 'r')
image = f.read('feature')
return (image)
\ No newline at end of file
return image
......@@ -2,22 +2,23 @@
# vim: set fileencoding=utf-8 :
# Pedro Tome <Pedro.Tome@idiap.ch>
import math
import numpy
import bob.core
import bob.io.base
import numpy
import math
#from math import pi
#from mumpy import sqrt
import scipy.signal
from facereclib.features.Extractor import Extractor
from bob.bio.base.features.Extractor import Extractor
from .. import utils
class MaximumCurvature (Extractor):
"""MiuraMax feature extractor
"""MiuraMax feature extractor based on
N. Miura, A. Nagasaka, and T. Miyatake, Extraction of Finger-Vein Pattern Using Maximum Curvature Points in Image Profiles.
Proceedings on IAPR conference on machine vision applications, 9 (2005), pp. 347--350
Based on N. Miura, A. Nagasaka, and T. Miyatake, Extraction of Finger-Vein
Pattern Using Maximum Curvature Points in Image Profiles. Proceedings on IAPR
conference on machine vision applications, 9 (2005), pp. 347--350
"""
......@@ -40,7 +41,8 @@ class MaximumCurvature (Extractor):
def maximum_curvature(self, image, mask):
"""Computes and returns the Maximum Curvature features for the given input fingervein image"""
"""Computes and returns the Maximum Curvature features for the given input
fingervein image"""
if image.dtype != numpy.uint8:
image = bob.core.convert(image,numpy.uint8,(0,255),(0,1))
......@@ -275,7 +277,4 @@ class MaximumCurvature (Extractor):
def read_feature(self, feature_file):
f = bob.io.base.HDF5File(feature_file, 'r')
image = f.read('feature')
return (image)
\ No newline at end of file
return image
......@@ -2,34 +2,28 @@
# vim: set fileencoding=utf-8 :
# Pedro Tome <Pedro.Tome@idiap.ch>
import bob.core
import bob.io.base
import numpy
from facereclib.features.Extractor import Extractor
class NormalisedCrossCorrelation (Extractor):
import bob.io.base
"""Normalised Cross-Correlation feature extractor based on
M. Kono, H. Ueki, and S.Umemura. Near-infrared finger vein patterns for personal
identification. Appl. Opt. 41(35):7429-7436, 2002
"""
from bob.bio.base.features.Extractor import Extractor
def __init__(
self,
):
class NormalisedCrossCorrelation (Extractor):
"""Normalised Cross-Correlation feature extractor
# call base class constructor
Extractor.__init__(
self,
Based on M. Kono, H. Ueki, and S.Umemura. Near-infrared finger vein patterns
for personal identification. Appl. Opt. 41(35):7429-7436, 2002
"""
)
def __init__(self):
Extractor.__init__(self)
# block parameters
def __call__(self, image, mask):
"""Reads the input image, extract the features based on Normalised Cross-Correlation of the fingervein image, and writes the resulting template"""
"""Reads the input image, extract the features based on Normalised
Cross-Correlation of the fingervein image, and writes the resulting
template"""
finger_image = image #Normalized image with histogram equalization
finger_mask = mask
......@@ -40,10 +34,12 @@ class NormalisedCrossCorrelation (Extractor):
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')
......
......@@ -4,26 +4,23 @@
import bob.io.base
import numpy
import math
#from math import pi
#from mumpy import sqrt
import scipy.signal
from facereclib.features.Extractor import Extractor
from .. import utils
from bob.bio.base.features.Extractor import Extractor
class MaximumCurvature (Extractor):
"""MiuraMax feature extractor
"""MiuraMax feature extractor based on
J.H. Choi, W. Song, T. Kim, S.R. Lee and H.C. Kim, Finger vein extraction using gradient normalization and principal curvature.
Proceedings on Image Processing: Machine Vision Applications II, SPIE 7251, (2009)
Based on J.H. Choi, W. Song, T. Kim, S.R. Lee and H.C. Kim, Finger vein
extraction using gradient normalization and principal curvature. Proceedings
on Image Processing: Machine Vision Applications II, SPIE 7251, (2009)
"""
def __init__(
self,
sigma = 2, # Gaussian standard deviation applied
threshold = 1.3, # Percentage of maximum used for hard thresholding
gpu = False
gpu = False,
):
# call base class constructor
......@@ -31,7 +28,7 @@ class MaximumCurvature (Extractor):
self,
sigma = sigma,
threshold = threshold,
gpu = gpu
gpu = gpu,
)
# block parameters
......@@ -41,7 +38,8 @@ class MaximumCurvature (Extractor):
def principal_curvature(self, image, mask):
"""Computes and returns the Maximum Curvature features for the given input fingervein image"""
"""Computes and returns the Maximum Curvature features for the given input
fingervein image"""
finger_mask = numpy.zeros(mask.shape)
finger_mask[mask == True] = 1
......@@ -89,7 +87,8 @@ class MaximumCurvature (Extractor):
def __call__(self, image):
"""Reads the input image, extract the features based on Principal Curvature of the fingervein image, and writes the resulting template"""
"""Reads the input image, extract the features based on Principal Curvature
of the fingervein image, and writes the resulting template"""
finger_image = image[0] #Normalized image with or without histogram equalization
finger_mask = image[1]
......@@ -101,10 +100,8 @@ class MaximumCurvature (Extractor):
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)
\ No newline at end of file
......@@ -2,23 +2,23 @@
# vim: set fileencoding=utf-8 :
# Pedro Tome <Pedro.Tome@idiap.ch>
import numpy
import math
import bob.core
import bob.io.base
import bob.ip.base
import numpy
import math
#from math import pi
#from mumpy import sqrt
import scipy.signal
from facereclib.features.Extractor import Extractor
from .. import utils
from bob.bio.base.features.Extractor import Extractor
class RepeatedLineTracking (Extractor):
"""Repeated Line Tracking feature extractor
"""Repeated Line Tracking feature extractor based on
N. Miura, A. Nagasaka, and T. Miyatake. Feature extraction of finger vein patterns based on repeated line tracking and its application
to personal identification. Machine Vision and Applications, Vol. 15, Num. 4, pp. 194--203, 2004
Based on N. Miura, A. Nagasaka, and T. Miyatake. Feature extraction of finger
vein patterns based on repeated line tracking and its application to personal
identification. Machine Vision and Applications, Vol. 15, Num. 4, pp.
194--203, 2004
"""
def __init__(
......@@ -26,7 +26,7 @@ class RepeatedLineTracking (Extractor):
iterations = 3000, # Maximum number of iterations
r = 1, # Distance between tracking point and cross section of the profile
profile_w = 21, # Width of profile (Error: profile_w must be odd)
rescale = True
rescale = True,
):
# call base class constructor
......@@ -35,7 +35,7 @@ class RepeatedLineTracking (Extractor):
iterations = iterations,
r = r,
profile_w = profile_w,
rescale = rescale
rescale = rescale,
)
# block parameters
......@@ -46,7 +46,8 @@ class RepeatedLineTracking (Extractor):
def repeated_line_tracking(self, finger_image, mask):
"""Computes and returns the MiuraMax features for the given input fingervein image"""
"""Computes and returns the MiuraMax features for the given input
fingervein image"""
#Convert image to uint8
if finger_image.dtype != numpy.uint8:
......@@ -208,6 +209,7 @@ class RepeatedLineTracking (Extractor):
return img_veins_bin.astype(numpy.float64)
def skeletonize(self, img):
import scipy.ndimage.morphology as m
h1 = numpy.array([[0, 0, 0],[0, 1, 0],[1, 1, 1]])
......@@ -233,7 +235,8 @@ class RepeatedLineTracking (Extractor):
def __call__(self, image):
"""Reads the input image, extract the features based on Maximum Curvature of the fingervein image, and writes the resulting template"""
"""Reads the input image, extract the features based on Maximum Curvature
of the fingervein image, and writes the resulting template"""
finger_image = image[0] #Normalized image with or without histogram equalization
finger_mask = image[1]
......@@ -249,5 +252,3 @@ class RepeatedLineTracking (Extractor):
f = bob.io.base.HDF5File(feature_file, 'r')
image = f.read('feature')
return (image)
\ No newline at end of file
......@@ -2,24 +2,23 @@
# vim: set fileencoding=utf-8 :
# Pedro Tome <Pedro.Tome@idiap.ch>
import bob.core
import bob.io.base
import bob.ip.base
import numpy
import math
#from math import pi
#from mumpy import sqrt
import scipy.signal
import scipy
import scipy.misc
from facereclib.features.Extractor import Extractor
from .. import utils
from bob.bio.base.features.Extractor import Extractor
class WideLineDetector (Extractor):
"""Wide Line Detector feature extractor
"""Wide Line Detector feature extractor based on
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
Based on 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.
"""
def __init__(
......@@ -27,8 +26,7 @@ class WideLineDetector (Extractor):
radius = 5, #Radius of the circular neighbourhood region
threshold = 1, #Neigborhood threshold
g = 41, #Sum of neigbourhood threshold
rescale = True
rescale = True,
):
# call base class constructor
......@@ -37,7 +35,7 @@ class WideLineDetector (Extractor):
radius = radius,
threshold = threshold,
g = g,
rescale = rescale
rescale = rescale,
)
# block parameters
......@@ -48,7 +46,8 @@ class WideLineDetector (Extractor):
def wide_line_detector(self, finger_image, mask):
"""Computes and returns the Wide Line Detector features for the given input fingervein image"""
"""Computes and returns the Wide Line Detector features for the given input
fingervein image"""
finger_image = finger_image.astype(numpy.float64)
......@@ -88,7 +87,8 @@ class WideLineDetector (Extractor):
def __call__(self, image):
"""Reads the input image, extract the features based on Wide Line Detector of the fingervein image, and writes the resulting template"""
"""Reads the input image, extract the features based on Wide Line Detector
of the fingervein image, and writes the resulting template"""
#For debugging
finger_image = image[0] #Normalized image with histogram equalization
......@@ -101,6 +101,7 @@ class WideLineDetector (Extractor):
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')
......
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
"""Feature Extraction"""
from NormalisedCrossCorrelation import NormalisedCrossCorrelation
from MaximumCurvature import MaximumCurvature
from RepeatedLineTracking import RepeatedLineTracking
from WideLineDetector import WideLineDetector
from LocalBinaryPatterns import LocalBinaryPatterns
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Pedro Tome <Pedro.Tome@idiap.ch>
import numpy.random
import scipy.ndimage
import numpy
import scipy.signal
import bob.ip.base
import bob.sp
......@@ -12,6 +10,7 @@ import bob.core
def imfilter(a, b, gpu=False, conv=True):
"""imfilter function based on MATLAB implementation."""
if (a.dtype == numpy.uint8):
a= bob.core.convert(a,numpy.float64,(0,1))
M, N = a.shape
......@@ -29,6 +28,3 @@ def imfilter(a, b, gpu=False, conv=True):
else:
return scipy.signal.convolve2d(a_ext, b, 'valid')
#return = self.convfft(a_ext, b)
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