classPiiLbp
#include <PiiLbp.h>
An implementation of the Local Binary Patterns (LBP) texture operator.
Description
The LBP works by comparing N pairs of pixels in a local neighborhood. The results of these comparisons build up a N-bit binary number. The process is repeated for each pixel in an image, and the codes are collected into a histogram. Alternatively, each pixel in the input image can be converted to a LBP code. The number of different LBP codes and hence the number of bins in the output histogram depends on LBP parameters. See Mode for details.
Usually, the local neighborhood in LBP is circular, parameterized by the number of samples and the neighborhood radius as shown in the picture below. (There are other alternatives, such as random neighborhood.) Each pixel in the neighborhood is compared to another pixel in the neighborhood. Depending on the result of the comparison, one bit of a binary number is set to either zero or one. Usually, the neighbors are compared to the pixel at the center of the circle. In symmetric LBP, opposing neighbors are compared to each other. In random LBP", the compared pixels are chosen at random.
Classes
| class |
A matrix class that creates a histogram. |
| class |
A matrix class that creates a feature image. |
Public types
|
enum
|
{ Standard, Uniform, RotationInvariant, UniformRotationInvariant,
Symmetric }
The operation mode of the LBP. |
Constructors and destructor
|
(
Creates a new LBP operator. |
|
|
( )
Destroy the LBP operator. |
Public member functions
|
template<class MatrixClass, class T, class Roi, class
UnaryFunction>
PiiMatrix< int >
|
A template function that extracts the LBP texture features from images. |
|
template<class MatrixClass, class T, class Roi>
PiiMatrix< int >
|
A convenience function that uses Pii::Identity as the center function. |
|
template<class MatrixClass, class T>
PiiMatrix< int >
|
A convenience function that uses PiiRoi::DefaultRoi and Pii::Identity as the region-of-interest and center function. |
|
template<class MatrixClass, class T, class Roi>
PiiMatrix< int >
|
Generic implementation of the symmetric LBP. |
|
template<class MatrixClass, class T>
PiiMatrix< int >
|
A convenience function that uses PiiRoi::DefaultRoi. |
|
( )
Returns the type of interpolation. |
|
|
( )
Returns the operation mode. |
|
|
double
|
Returns the neighborhood radius. |
|
int
|
( )
Returns the number of neighborhood samples. |
|
void
|
Sets LBP parameters. |
Static public member functions
|
template<class MatrixClass, class T, class Roi, class
UnaryFunction>
static PiiMatrix< int
>
|
A highly optimized template implementation of the LBP 8,1 operator with nearest neighbor "interpolation". |
|
template<class MatrixClass, class T, class Roi>
static PiiMatrix< int
>
|
A highly optimized template implementation of the LBP 8,1 operator with nearest neighbor "interpolation". |
|
template<class MatrixClass, class T>
static PiiMatrix< int
>
|
A convenience function that uses PiiRoi::DefaultRoi as the region-of-interest and Pii::Identity as the center function. |
|
template<class MatrixClass, class T>
static PiiMatrix< int
>
|
A convenience function that uses PiiRoi::DefaultRoi. |
|
template<class MatrixClass, class T, class Roi>
static PiiMatrix< int
>
|
Same as above, but optimized for the 8-neighbors. |
|
static unsigned short *
|
Returns a look-up table for converting standard LBP codes to, for example, rotation invariant ones. |
|
static int
|
Returns the length of the feature vector an LBP operation with the given parameters will produce. |
Enumeration details
-
enum Mode
The operation mode of the LBP.
Possible values are:
-
Standard- no modifications. All binary codes build up their own histogram bins. The total number of bins is
. For example, an 8-bit LBP produces a
256-bin histogram.
-
Uniform- only "uniform" binary codes are accepted. Others build up a single "miscellaneous" bin. This reduces the number of bins significantly and increases robustness in some applications. Uniform binary codes are binary numbers that have at most two 1-to-0 or 0-to-1 transitions in their circularly interpreted binary representation. For example, the 8-bit binary number 10000011 is uniform whereas 10000101 is not. -
RotationInvariant- each code is rotated to its minimum value so that rotation of the image does not (ideally) change the result. This reduces the number of codes. For example, the 8-bit codes 11100000, 01110000, and 00111000 would all become 00000111. -
UniformRotationInvariant- likeRotationInvariant, but only uniform codes are accepted. This results in a short, rotation invariant feature vector. -
Symmetric- An LBP operator that compares opposing pairs of pixels in a circular neighborhood and ignores the center. The advantage is that only N/2 comparisons per pixel are needed compared to N comparisons in the original LBP operator. Furthermore, the length of the (standard) feature vector will be
instead of
, which makes classification faster.
Unfortunately, there is no free lunch. The symmetric version cannot
be made rotation invariant as easily as the basic LBP. Its
classification accuracy may also be somewhat worse. Uniform
patterns and rotation invariance loose their meaning with the
symmetric LBP.
-
Function details
-
PiiLbp
(- int samples = 8
- double radius = 1
- Mode mode = Standard
- Pii::Interpolation interpolation = Pii::NearestNeighborInterpolation
Creates a new LBP operator.
Parameters
- samples
-
the number of neighborhood samples
- radius
-
the radius of the neighborhood
- mode
-
the operation mode
- interpolation
-
interpolation mode
-
~PiiLbp
()Destroy the LBP operator.
-
template<class MatrixClass, class T, class Roi, class UnaryFunction>
PiiMatrix< int > genericLbp
A template function that extracts the LBP texture features from images.
The function works with all primitive types. This function is an entry point that selects the appropriate optimized LBP implementation based on the current mode.
The template parameter
Tis for the primitive type.MatrixClassis a special class derived from PiiMatrix<int> that has a known structure. By changing this class one can use the LBP operator to create either histograms or feature images. See PiiLbp::Histogram and PiiLbp::Image for details.PiiMatrix<int> image; PiiLbp lbp; lbp.genericLbp<PiiLbp::Histogram>(image, PiiRoi::DefaultRoi(), Pii::Identity<int>()); // Outputs histogram lbp.genericLbp<PiiLbp::Image>(image, PiiRoi::DefaultRoi(), std::bind2nd(std::plus<int>(), 3)); // Outputs feature image
Parameters
- image
-
the input image
- roi
-
region-of-interest. See PiiRoi.
- centerFunc
-
the "center function" is applied to each pixel before comparing it to the neighbors. See basicLbp().
-
A convenience function that uses Pii::Identity as the center function.
-
A convenience function that uses PiiRoi::DefaultRoi and Pii::Identity as the region-of-interest and center function.
-
template<class MatrixClass, class T, class Roi>
PiiMatrix< int > genericSymmetricLbp
Generic implementation of the symmetric LBP.
-
A convenience function that uses PiiRoi::DefaultRoi.
-
Pii::Interpolation interpolation
()Returns the type of interpolation.
-
Mode mode
()Returns the operation mode.
-
double neighborhoodRadius
()Returns the neighborhood radius.
-
int sampleCount
()Returns the number of neighborhood samples.
-
void setParameters
Sets LBP parameters.
Calling this function will update mapping tables and interpolation coefficients.
Parameters
- samples
-
the number of neighborhood samples. The basic LBP uses eight neighbors. 16 is a common choice, and even 24 can be used, but with 24 samples, a 32MB look-up table is needed.
- radius
-
the neighborhood radius. The radius can, in principle, take any value, but typically only discrete values in the range 1 ... 5 are used. The basic LBP uses 1 as the radius.
- mode
-
the operation mode.
- interpolation
-
the type of interpolation. Due to the circular neighborhood, not all samples fall exactly on pixels. For such samples, interpolation is needed. Supported interpolation types are
NearestNeighborInterpolationandLinearInterpolation. The default is nearest neighbor.
-
template<class MatrixClass, class T, class Roi, class UnaryFunction>
static PiiMatrix< int > basicLbp
[static]A highly optimized template implementation of the LBP 8,1 operator with nearest neighbor "interpolation".
The function works with all primitive types.
PiiMatrix<unsigned char> image; PiiLbp::basicLbp<PiiLbp::Histogram>(image, PiiRoi::DefaultRoi(), std::bind2nd(std::plus<unsigned>(), 4));
Please ensure that the result type of
centerFunccan store the calculation result without overflows or underflows. For example, usingunsignedcharis not a good idea because 255 + 4 = 3.Parameters
- image
-
the input image
- roi
-
region-of-interest. See PiiRoi.
- centerFunc
-
the "center function" is applied to each pixel before comparing it to the neighbors. For example, a useful trick to increase LBP's noise tolerance is to add a constant value to the center pixel before comparing it to neighbors:
-
A highly optimized template implementation of the LBP 8,1 operator with nearest neighbor "interpolation".
The function works with all primitive types. This version uses Pii::Identity as the center function.
-
A convenience function that uses PiiRoi::DefaultRoi as the region-of-interest and Pii::Identity as the center function.
-
A convenience function that uses PiiRoi::DefaultRoi.
-
Same as above, but optimized for the 8-neighbors.
-
Returns a look-up table for converting standard LBP codes to, for example, rotation invariant ones.
The size of the table will be 2^samples. Thus, a look-up table for LBP24 eats up 32MB of memory. For LBP16, the size is 128kB, which is a practical upper limit.
Parameters
- samples
- mode
-
the operator type the codes are mapped to
-
Returns the length of the feature vector an LBP operation with the given parameters will produce.
Parameters
- samples
-
the number of neighborhood samples
- mode
-
the mode of the operator
Returns
the length of the feature vector. The result for "Standard" mode is 2^samples. Other modes produce less features.
Add a note
Not a single note added yet. Be the first, add yours.