LBP (local Binary pattern, partial two-value mode) is an operator used to describe the local texture feature of an image, and it has the notable advantages of rotational invariance and grayscale invariance. It is first by T. Ojala, M.pietik?inen, and D. Harwood was introduced in 1994 for Texture feature extraction. Moreover, the extracted feature is the local texture feature of the image;
1. Description of LBP features
The original LBP operator is defined in the window of the 3*3, with the window center pixel as the threshold value, the adjacent 8 pixels of the gray value of the comparison with its, if the surrounding pixel value is greater than the center pixel value, then the location of the pixel is marked 1, otherwise 0. In this way, 8 points in the 3*3 neighborhood can be compared to produce 8-bit binary numbers (typically converted to a decimal number, or LBP code, a total of 256), which is the LBP value of the center pixel of the window, and this value is used to reflect the texture information of the region. As shown in the following illustration:
An improved version of LBP:
After the original LBP was proposed, the researchers continued to propose various improvements and optimizations.
(1) Circular LBP operator:
The biggest drawback of the basic LBP operator is that it covers only a small area within a fixed radius, which obviously does not meet the needs of different sizes and frequency textures. In order to adapt to the texture characteristics of different scales, and to achieve the requirements of grayscale and rotational invariance, Ojala has improved the LBP operator, extended the 3x3 neighborhood to any neighborhood, and replaced the Square neighborhood with a circular neighborhood, and the improved LBP operator allows any number of pixels in a circular neighborhood with a radius of R. The LBP operator with P sampling points in a circular region with radius r is obtained.
(2) LBP rotation invariant mode
It can be seen from the definition of LBP that the LBP operator is invariant in grayscale, but not rotated. The rotation of the image will get different LBP values.
Maenpaa and other people have extended the LBP operator, and a LBP operator with rotational invariance is proposed, that is, a series of initial defined LBP values are obtained by rotating the circular neighborhood, taking its minimum value as the LBP value of the neighborhood.
Figure 2.5 shows a diagram of the process for obtaining a rotation-invariant LBP, the numbers below the operator indicate the LBP value of the operator, the 8 LBP patterns shown in the figure, the rotation-invariant processing, the resulting LBP value of rotation invariance is 15. In other words, the 8 LBP patterns in the graph correspond to a rotation-invariant LBP pattern of 00001111.
(3) LBP equivalent mode
A LBP operator can produce different binary modes, and the LBP operator with P sampling points in a circular region with radius r will produce P2 patterns. Obviously, with the increase in the number of sampling points in the neighborhood set, the type of binary mode is sharply increased. For example, 20 sample points within a 5x5 neighborhood, with 220 = 1,048,576 binary modes. So many of the two value patterns are not good for texture extraction or texture recognition, classification, and access to information. At the same time, too many pattern types are detrimental to the expression of textures. For example, when the LBP operator is used for texture classification or face recognition, the statistical histogram of LBP is used to express the information of the image, and more pattern types will make the data too large and the histogram is too sparse. Therefore, it is necessary to reduce the dimensionality of the original LBP pattern, which can best represent the information of the image when the data volume is reduced.
In order to solve the problem of too much binary mode and improve the statistic, Ojala proposes to use an "equivalence pattern" (Uniform pattern) to reduce the dimensionality of the pattern types of LBP operators. Ojala that the majority of LBP patterns in real images contain up to two jumps from 1 to 0 or 0 to 1. As a result, Ojala defines "equivalence mode" as the binary equivalent of a LBP that is referred to as an equivalence pattern class when the corresponding cyclic binary number from 0 to 1 or from 1 to 0 is changed by a maximum of two times. such as 00000000 (0 jumps), 00000111 (only one time from 0 to 1 of the jump), 10001111 (first from 1 to 0, then 0 to 1, a total of two jumps) are equivalent pattern classes. Patterns other than equivalence mode classes are classified as a mixed-mode class, such as 10010111 (a total of four jumps) (this is my personal understanding, not knowing right).
With this improvement, the type of binary mode is greatly reduced without any loss of information. The number of patterns is reduced from the original 2P species to P (P-1) + 2, where p represents the sample count in the neighborhood set. For 8 sample points in a 3x3 neighborhood, the binary mode is reduced from 256 to 58, which makes the eigenvectors less dimensional and reduces the impact of high-frequency noise.
2. The principle of LBP features for testing
It is obvious that the extracted LBP operator can get a LBP "code" at each pixel point, then, after extracting its original LBP operator for an image (the grayscale value of each pixel is recorded), the original LBP feature is still "a picture" (the LBP value of each pixel is recorded).
In the application of LBP, such as texture classification, face analysis and so on, the LBP map is not used as eigenvector for classification recognition, but the statistical histogram of LBP feature spectrum is used as feature vector for classification recognition.
Because, from the above analysis, we can see that this "feature" is closely related to the position information. Directly to two pictures to extract this "feature", and the discriminant analysis, will be because "position is not aligned" and produced a great error. Later, the researchers found that a picture could be divided into sub-regions, extracting LBP features for each pixel in each sub-region, and then establishing a statistical histogram of LBP features within each sub-region. As a result, each sub-region can be described by a statistical histogram, and the whole picture is composed of several statistical histograms;
For example, a 100*100 pixel-sized picture, divided into 10*10=100 sub-regions (which can be divided in several ways), each sub-region is 10*10 pixels, each pixel within each sub-region extracts its LBP feature, and then a statistical histogram is established; This picture has a 10*10 sub-area, there is a 10*10 statistical histogram, using this 10*10 statistical histogram, you can describe this picture. Then, we can judge the similarity between the two images by using various similarity measure functions.
3. The process of extracting LBP eigenvector
(1) First, the detection window is divided into 16x16 small area (cell);
(2) for one pixel in each cell, compare the gray values of the adjacent 8 pixels with their values, if the surrounding pixel value is greater than the center pixel value, the pixel position is marked as 1, otherwise 0. Thus, the 8 points in the 3*3 neighborhood can produce a 8-bit binary number, that is, the LBP value of the center pixel of the window is obtained;
(3) The histogram of each cell is then computed, that is, the frequency at which each number (assuming the value of the decimal number LBP) occurs, and the histogram is normalized.
(4) Finally, the resulting statistical histogram of each cell is connected to become a eigenvector, that is, the LBP texture feature vector of the whole picture;
You can then use SVM or other machine learning algorithms to classify it.
4 and the implementation of LBP features (Reference blog: http://blog.csdn.net/jinshengtao/article/details/18219697)
The following code is implemented in C, reads a grayscale image, the number of sample points, the sampling radius, the LBP feature is calculated for each pixel and output, LBP image and its histogram.
For rotation invariance and uniform rotation invariance, I do not have the above formula for each pixel operation, because it is a circular loop of 2, you can do a mapping mapping in advance, speed up the program execution speed.
The number of sample points is 8 and the sampling radius is 10
Input Image:
4.1 Grayscale invariance LBP:[CPP] View plain copy VOID&NBSP;GRAY_INVARIANT_LBP (iplimage *src,int height,int width,int num _sp,mypoint *spoint) { IplImage *target,*hist; int i,j,k,box_x,box_y,orign_x,orign_y,dx,dy,tx,ty,fy,fx,cy,cx,v; double min_x,max_x,min_y,max_y,w1,w2,w3,w4,N,x,y; int *result; float dishu; dishu = 2.0; max_ x=0;max_y=0;min_x=0;min_y=0; for (k=0;k<num_sp;k++) { if (max_x<spoint[ k].x) { max_x=spoint[k].x;