Commit be661567 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Add LBP Histograms

parent 1c31fe22
Pipeline #8842 failed with stages
in 6 minutes and 43 seconds
from . import script
from . import algorithm, extractor, preprocessor
def get_config():
"""Returns a string containing the configuration information.
"""
"""Returns a string containing the configuration information.
"""
import bob.extension
return bob.extension.get_config(__name__)
import bob.extension
return bob.extension.get_config(__name__)
# gets sphinx autodoc done right - don't remove it
......
from __future__ import division
from bob.bio.base.extractor import Extractor
import bob.bio.video
import bob.ip.base
import numpy
class LBPHistogram(Extractor):
"""Calculates a normalized LBP histogram over an image.
These features are implemented based on the chingovska_effectiveness_2012_.
Parameters
----------
lbptype : str
The type of the LBP operator (regular, uniform or riu2)
elbptype : str
The type of extended version of LBP (regular if not extended version
is used, otherwise transitional, direction_coded or modified)
rad : float
The radius of the circle on which the points are taken (for circular
LBP)
neighbors : int
The number of points around the central point on which LBP is
computed (4, 8, 16)
circ : bool
True if circular LBP is needed, False otherwise
Attributes
----------
dtype : numpy.dtype
If a ``dtype`` is specified in the contructor, it is assured that the
resulting features have that dtype.
lbp : bob.ip.base.LBP
The LPB extractor object.
.. _chingovska_effectiveness_2012:
I. Chingovska, A. Anjos, and S. Marcel, ``On the effectiveness of
local binary patterns in face anti-spoofing,'' in Biometrics Special
Interest Group (BIOSIG), 2012 BIOSIG-Proceedings of the International
Conference of the, 2012, pp. 1-7.
"""
def __init__(self,
lbptype='uniform',
elbptype='regular',
rad=1,
neighbors=8,
circ=False,
dtype=None):
super(LBPHistogram, self).__init__(
lbptype=lbptype,
elbptype=elbptype,
rad=rad,
neighbors=neighbors,
circ=circ,
dtype=dtype,)
elbps = {'regular': 'regular',
'transitional': 'trainsitional',
'direction_coded': 'direction-coded',
'modified': 'regular'}
if elbptype == 'modified':
mct = True
else:
mct = False
if lbptype == 'uniform':
if neighbors == 16:
lbp = bob.ip.base.LBP(
neighbors=16, uniform=True, circular=circ,
radius=rad, to_average=mct, elbp_type=elbps[elbptype])
else: # we assume neighbors==8 in this case
lbp = bob.ip.base.LBP(
neighbors=8, uniform=True, circular=circ,
radius=rad, to_average=mct, elbp_type=elbps[elbptype])
elif lbptype == 'riu2':
if neighbors == 16:
lbp = bob.ip.base.LBP(
neighbors=16, uniform=True, rotation_invariant=True,
radius=rad, circular=circ, to_average=mct,
elbp_type=elbps[elbptype])
else: # we assume neighbors==8 in this case
lbp = bob.ip.base.LBP(
neighbors=8, uniform=True, rotation_invariant=True,
radius=rad, circular=circ, to_average=mct,
elbp_type=elbps[elbptype])
else: # regular LBP
if neighbors == 16:
lbp = bob.ip.base.LBP(
neighbors=16, circular=circ, radius=rad, to_average=mct,
elbp_type=elbps[elbptype])
else: # we assume neighbors==8 in this case
lbp = bob.ip.base.LBP(
neighbors=16, circular=circ, radius=rad, to_average=mct,
elbp_type=elbps[elbptype])
self.dtype = dtype
self.lbp = lbp
def __call__(self, data):
"""Extracts LBP histograms from a gray-scale image.
Takes data of arbitrary dimensions and linearizes it into a 1D vector;
Then, calculates the histogram.
enforcing the data type, if desired.
Parameters
----------
data : numpy.ndarray
The preprocessed data to be transformed into one vector.
Returns
-------
1D :py:class:`numpy.ndarray`
The extracted feature vector, of the desired ``dtype`` (if
specified)
"""
assert isinstance(data, numpy.ndarray)
# allocating the image with lbp codes
lbpimage = numpy.ndarray(self.lbp.lbp_shape(data), 'uint16')
self.lbp(data, lbpimage) # calculating the lbp image
hist = bob.ip.base.histogram(
lbpimage, (0, self.lbp.max_label - 1), self.lbp.max_label)
hist = hist / sum(hist) # histogram normalization
if self.dtype is not None:
hist = hist.astype(self.dtype)
return hist
# re-define unused functions, just so that they do not get documented
def train(*args, **kwargs):
raise NotImplementedError()
def load(*args, **kwargs):
pass
from .LBPHistogram import LBPHistogram
def __appropriate__(*args):
"""Says object was actually declared here, and not in the import module.
Fixing sphinx warnings of not being able to find classes, when path is
shortened.
Parameters
----------
*args
The objects that you want sphinx to beleive that are defined here.
Resolves `Sphinx referencing issues <https//github.com/sphinx-
doc/sphinx/issues/3048>`
"""
for obj in args:
obj.__module__ = __name__
__appropriate__(
LBPHistogram,
)
__all__ = [_ for _ in dir() if not _.startswith('_')]
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
"""Prints the version of bob and exits
"""
def main():
"""Main routine, called by the script that gets the configuration of bob.blitz"""
import bob.blitz
print (bob.blitz.get_config())
return 0
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
"""Test Units
"""
def test_version():
from .script import version
assert version.main() == 0
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
"""Test Units
"""
import numpy as np
from bob.io.base.test_utils import datafile
from bob.io.base import load
import bob.io.image # for image loading functionality
from bob.ip.color import rgb_to_gray
from ..extractor import LBPHistogram
def test_lbp_histogram():
lbp = LBPHistogram()
img = load(datafile('testimage.jpg', 'bob.bio.face.test'))
img = rgb_to_gray(img)
features = lbp(img)
reference = load(datafile('lbp.hdf5', 'bob.pad.face.test'))
assert np.allclose(features, reference)
.. py:currentmodule:: bob.pad.face
.. testsetup:: *
from __future__ import print_function
import pkg_resources
============================================================
Presentation Attack Detection in Face Biometrics in Python
============================================================
MFCC Extraction
---------------
Two funct
.. vim: set fileencoding=utf-8 :
.. Andre Anjos <andre.anjos@idiap.ch>
.. Mon 13 Aug 2012 12:36:40 CEST
.. _bob.pad.face:
......@@ -8,10 +6,15 @@
Presentation Attack Detection in Face Biometrics
==================================================
.. todolist::
Package Documentation
---------------------
.. automodule:: bob.pad.face
.. toctree::
:maxdepth: 2
guide
py_api
.. vim: set fileencoding=utf-8 :
===================================
Tools implemented in bob.pad.face
===================================
Summary
-------
Databases
~~~~~~~~~
Image Preprocessors
~~~~~~~~~~~~~~~~~~~
Video Preprocessors
~~~~~~~~~~~~~~~~~~~
Image Extractors
~~~~~~~~~~~~~~~~
Image Extractors
~~~~~~~~~~~~~~~~
.. autosummary::
bob.pad.face.extractor.LBPHistogram
Video Extractors
~~~~~~~~~~~~~~~~
.. automodule:: bob.pad.face
Image Extractors
----------------
.. automodule:: bob.pad.face.extractor
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