C/C++ API¶
This section includes information for using the C or C++ API of bob::ip::gabor.
The pure C++ API of the classes in bob::ip::gabor can be obtained through including the specific header files, which will be described below, e.g.:
#include <bob.ip.gabor/Wavelet.h>
On the other hand, to leverage from the pure C API, you simply need to include:
#include <bob.ip.gabor/api.h>
C++ API¶
The classes and functions in the C++ API are all contained in the bob::ip::gabor namespace.
All classes from the Python API are reflected in the C++ API as well.
Particularly:
Gabor wavelet¶
-
class
bob::ip::gabor::Wavelet¶ Implements the Gabor wavelet in C++, which is defined in frequency domain as:
(1)

-
Wavelet(const blitz::TinyVector<int, 2> &resolution, const blitz::TinyVector<double, 2> &wavelet_frequency, const double sigma = 2. * M_PI, const double pow_of_k = 0., const bool dc_free = true, const double epsilon = 1e-10)¶ Constructor taking the image resolution, the wavelet frequency
, the width of the enveloping Gaussian
and the
value power_of_k. Whendct_freeis set tofalse, the second part of (1) will not be added. For efficiency reasons, the Gabor wavelet is not implemented as an image, but wavelet values that are lower than the givenepsilonare discarded.
-
blitz::Array<double, 2>
waveletImage() const¶ Computes and returns an image containing the Gabor wavelet in frequency domain.
-
transform(const blitz::Array<std::complex<double>, 2> &frequency_domain_image, blitz::Array<std::complex<double>, 2> &transformed_frequency_domain_image) const¶ Performs the Gabor wavelet transform with a single Gabor wavelet on the given
frequency_domain_imageand writes it’s result into thetransformed_frequency_domain_image. Note that both images are of complex type and considered to be in frequency domain.
-
Gabor wavelet family¶
-
class
bob::ip::gabor::Transform¶ Implements a family of Gabor wavelets used to perform a Gabor wavelet transform. Gabor wavelets are extracted for a given number of scales and directions, which will result in several
vectors for the (1):(2)

with:
(3)

-
Transform(int number_of_scales = 5, int number_of_directions = 8, double sigma = 2. * M_PI, double k_max = M_PI / 2., double k_fac = 1./sqrt(2.), double pow_of_k = 0., bool dc_free = true, double epsilon = 1e-10)¶ Constructor taking the
number_of_scales
, the number_of_orientations
, the k_max
and the k_fac
as given in (3).
The parameters sigma,pow_of_k,dc_freeandepsilonare directly passed to theWaveletconstructor.Note
The Gabor wavelets are not generated in this constructor since the image resolution is not known at construction time. The wavelets will only be generated during a call to
transform()or togenerateWavelets().
-
void
transform(const blitz::Array<T, 2> &gray_image, blitz::Array<std::complex<double>, 3> &trafo_image)¶ Computes a Gabor wavelet transform on the given image, which can be of various types
T. If needed, this function will automatically callgenerateWavelets()with the current image resolution. The resultingtrafo_imagemust have the shape (numberOfWavelets(),grap_image.extent(0),grap_image.extent(1)).
-
void
generateWavelets(int y_resoultion, int x_resolution)¶ Generates the family of Gabor wavelets for the given image resolution.
-
std::vector<blitz::TinyVector<double, 2>> &
waveletFrequencies() const¶ Returns the list of frequencies
as defined in (2) for all wavelets stored in this family.
-
std::vector<boost::shared_ptr<bob::ip::gabor::Wavelet>> &
wavelets() const¶ Provides the list of
Wavelets which are stored in this class.Note
This list will be empty until either of
transform()orgenerateWavelets()is called.
-
int
numberOfWavelets() const¶ Returns the number of wavelets of this Gabor wavelet family, i.e.,
.
-
void
load(bob::io::base::HDF5File &file)¶ Loads the configuration of this Gabor wavelet family from the given
bob::io::base::HDF5File.Note
No wavelets are created in after loading the configuration.
-
void
save(bob::io::base::HDF5File &file) const¶ Saves the configuration of this Gabor wavelet family to the given
bob::io::base::HDF5File.
-
Gabor jet¶
-
class
bob::ip::gabor::Jet¶ An implementation of a Gabor jet, which is a local texture descriptor by collecting all wavelet responses of a given
Transformobject. Gabor jets store the wavelet responses in polar form, i.e., storing the absolute valuesabs()and the phasesphase(). In this implementation, the Gabor phases are always extracted, and by default, the vector of absolute values of the Gabor jets is normalized to unit Euclidean length.-
Jet(int length = 0)¶ Default constructor that generates an uninitialized Gabor jet of the given length
-
Jet(const blitz::Array<std::complex<double>, 3> &trafo_image, const blitz::TinyVector<int, 2> &position, bool normalize = true)¶ Extracts a Gabor jet at the given
locationfrom thetrafo_image, which usually is a result of theTransform::transform()function.
-
Jet(const blitz::Array<std::complex<double>, 1> &data, bool normalize = true)¶ Creates a Gabor jet from the given vector of complex-valued data.
Creates a Gabor jet by averaging the given Gabor jets, which need to be of the same length.
-
double
normalize()¶ Normalizes the absolute values of the Gabor jet to unit Euclidean length and return its old Euclidean length.
-
blitz::Array<double, 2> &
jet()¶ Returns the absolute and phase values of this Gabor jet, where
jet()(0,.)contains the absolute values, whilejet()(1,.)comprises the phases.
-
const blitz::Array<double, 1> &
abs()¶ Returns the absolute values of this Gabor jet, i.e.,
jet()(0).
-
const blitz::Array<double, 1> &
phase()¶ Returns the phase values of this Gabor jet, i.e.,
jet()(1).
-
const blitz::Array<std::complex<double>, 1>
complex() const¶ Returns a complex-valued representation of the Gabor jet, which is computed on the fly.
-
int
length() const¶ Returns the length of this Gabor jet, which is usually the number of wavelets
Transform::numberOfWavelets(), i.e.,
.
-
void
load(bob::io::base::HDF5File &file)¶ Loads the Gabor jet from the given
bob::io::base::HDF5File.
-
void
save(bob::io::base::HDF5File &file) const¶ Saves the Gabor jet to the given
bob::io::base::HDF5File.
-
Gabor jet similarity¶
-
class
bob::ip::gabor::Similarity¶ Implements several Gabor jet similarity functions, which will compute the similarity of two
Jets. Currently, several types are implemented, see the documentation for the Python classbob.ip.gabor.Jetfor a list of implemented functions.-
class
SimilarityType¶ Enumeration to define the type of the similarity function to be computed.
Constructor to create a Gabor jet similarity function of the given
SimilarityType. Some types of similarity functions require theTransformwith which theJets are extracted.
-
double
similarity(const Jet &jet1, const Jet &jet2) const¶ Computes the similarity of the two Gabor jets using.
-
blitz::TinyVector<double, 2>
disparity(const Jet &jet1, const Jet &jet2) const¶ Estimates the disparity vector between the given two Gabor jets. For some similarity functions, the
disparity()is computed and stored.
-
blitz::TinyVector<double, 2>
disparity() const¶ Returns the disparity vector estimated in the last call to
similarity().Note
Not all similarity function compute the disparity. Hence, the returned values might be
NaN.
-
shift_phase(const Jet &jet, const Jet &reference, Jet &shifted) const¶ Shifts the
Jet::phase()values of thejettowards thereferencesuch that thedisparity(shifted, reference) == (0., 0.).
-
void
load(bob::io::base::HDF5File &file)¶ Loads the configuration of this Gabor jet similarity from the given
bob::io::base::HDF5File.
-
void
save(bob::io::base::HDF5File &file) const¶ Saves the configuration of this Gabor jet similarity to the given
bob::io::base::HDF5File.
-
class
Gabor graph¶
-
class
bob::ip::gabor::Graph¶ Extracts several Gabor jets from a given image using a fixed set of locations, which usually form a grid.
-
Graph(blitz::TinyVector<int, 2> righteye, blitz::TinyVector<int, 2> lefteye, int between, int along, int above, int below)¶ Generates a grid graph extractor which is aligned to the given eye positions. When the eye positions are not on a horizontal line, the grid will be slanted. In the graph, there will be
betweennodes placed in between the eye positions,alongnodes to the left and to the right of the eyes,abovenodes above the eyes andbelownodes below the eyes. Hence, in total(2*along + between + 2) X (above + below + 1)nodes will be created.
-
Graph(blitz::TinyVector<int, 2> first, blitz::TinyVector<int, 2> last, blitz::TinyVector<int, 2> step)¶ Generates a grid graph extractor which will extract regular grid graphs. The first node is extracted at the given
firstposition, the next nodes will be placedsteppixels further (where horizontal and vertical steps are handled independently), and the last node is placed at or before the givenlastnode.
-
Graph(const std::vector<blitz::TinyVector<int, 2>> &nodes)¶ Constructs a graph extractor using the given nodes.
Extracts Gabor jets from the given
trafo_image(which is usually the result of a call toTransform::transform(). The extracted Gabor jets will be placed into the givenjetsvector, which might be empty or contain Gabor jets, which will be updated.
-
nodes(const std::vector<blitz::TinyVector<int, 2>> &nodes)¶ Replaces the nodes of this graph with the given ones.
-
const std::vector<blitz::TinyVector<int, 2>> &
nodes() const¶ Returns the node positions of this graph.
-
void
load(bob::io::base::HDF5File &file)¶ Loads the configuration of this graph extractor from the given
bob::io::base::HDF5File.
-
void
save(bob::io::base::HDF5File &file) const¶ Saves the configuration of this graph extractor to the given
bob::io::base::HDF5File.
-
C API¶
The C-API can be used in the Python bindings, when you need to reference a C++ class of the bob::ip::gabor namespace.
When you use the C++ API in a derived package Python bindings, please make sure that you import this package, as well as the dependencies bob.blitz, bob.io.base and bob.sp, by adding the following lines to your module definition:
#include <bob.blitz/capi.h>
#include <bob.io.base/api.h>
#include <bob.sp/api.h>
#include <bob.ip.gabor/api.h>
PyMODINIT_FUNC initclient(void) {
...
/* imports dependencies */
if (import_bob_blitz() < 0) {
PyErr_Print();
PyErr_SetString(PyExc_ImportError, "cannot import extension");
return 0;
}
if (import_bob_io_base() < 0) {
PyErr_Print();
PyErr_SetString(PyExc_ImportError, "cannot import extension");
return 0;
}
if (import_bob_sp() < 0) {
PyErr_Print();
PyErr_SetString(PyExc_ImportError, "cannot import extension");
return 0;
}
if (import_bob_ip_gabor() < 0) {
PyErr_Print();
PyErr_SetString(PyExc_ImportError, "cannot import extension");
return 0;
}
...
}
For each of the five classes above, there exist three objects that can be used in the bindings.
These objects are defined in the api.h header file:
Gabor wavelet¶
-
PyBobIpGaborWaveletObject¶ -
boost::shared_ptr<bob::ip::gabor::Wavelet>
cxx¶ The shared pointer to object of the underlying
bob::ip::gabor::Waveletclass.
-
boost::shared_ptr<bob::ip::gabor::Wavelet>
-
PyTypeObject
PyBobIpGaborWavelet_Type¶ The
PyTypeObjectthat defines thebob::ip::gabor::Waveletclass.
-
int
PyBobIpGaborWavelet_Check(PyObject* o)¶ The function to check if the given
PyObjectis castable to aPyBobIpGaborWaveletObject. It returns1if it is, and0otherwise.
Gabor wavelet family¶
-
PyBobIpGaborTransformObject¶ -
boost::shared_ptr<bob::ip::gabor::Transform>
cxx¶ The shared pointer to object of the underlying
bob::ip::gabor::Transformclass.
-
boost::shared_ptr<bob::ip::gabor::Transform>
-
PyTypeObject
PyBobIpGaborTransform_Type¶ The
PyTypeObjectthat defines thebob::ip::gabor::Transformclass.
-
int
PyBobIpGaborTransform_Check(PyObject* o)¶ The function to check if the given
PyObjectis castable to aPyBobIpGaborTransformObject. It returns1if it is, and0otherwise.
Gabor jet¶
-
PyBobIpGaborJetObject¶ -
boost::shared_ptr<bob::ip::gabor::Jet>
cxx¶ The shared pointer to object of the underlying
bob::ip::gabor::Jetclass.
-
boost::shared_ptr<bob::ip::gabor::Jet>
-
PyTypeObject
PyBobIpGaborJet_Type¶ The
PyTypeObjectthat defines thebob::ip::gabor::Jetclass.
-
int
PyBobIpGaborJet_Check(PyObject* o)¶ The function to check if the given
PyObjectis castable to aPyBobIpGaborJetObject. It returns1if it is, and0otherwise.
Gabor jet similarity¶
-
PyBobIpGaborSimilarityObject¶ -
boost::shared_ptr<bob::ip::gabor::Similarity>
cxx¶ The shared pointer to object of the underlying
bob::ip::gabor::Similarityclass.
-
boost::shared_ptr<bob::ip::gabor::Similarity>
-
PyTypeObject
PyBobIpGaborSimilarity_Type¶ The
PyTypeObjectthat defines thebob::ip::gabor::Similarityclass.
-
int
PyBobIpGaborSimilarity_Check(PyObject* o)¶ The function to check if the given
PyObjectis castable to aPyBobIpGaborSimilarityObject. It returns1if it is, and0otherwise.
Gabor graph¶
-
PyBobIpGaborGraphObject¶ -
boost::shared_ptr<bob::ip::gabor::Graph>
cxx¶ The shared pointer to object of the underlying
bob::ip::gabor::Graphclass.
-
boost::shared_ptr<bob::ip::gabor::Graph>
-
PyTypeObject
PyBobIpGaborGraph_Type¶ The
PyTypeObjectthat defines thebob::ip::gabor::Graphclass.
-
int
PyBobIpGaborGraph_Check(PyObject* o)¶ The function to check if the given
PyObjectis castable to aPyBobIpGaborGraphObject. It returns1if it is, and0otherwise.