Facial recognition feature extraction (LBP) and its OPENCV implementation

Source: Internet
Author: User

LBP is a simple and effective feature extraction algorithm for texture classification. The LBP operator was presented in 1996 by Ojala and others, and the main thesis is "Multiresolution gray-scale and rotation invariant texture with the local Binary patterns ", Pami, vol., No.7, July 2002. LBP is the abbreviation of "Local binary pattern". The local two-value pattern is a simple but very efficient texture operator. It compares each pixel to its nearby pixel and saves the result as a binary number. Because of its strong distinguishing ability and simple calculation, local two-valued pattern texture operators have been applied in different scenarios. The most important attribute of LBP is the robustness of grayscale changes, such as illumination changes. Another important feature of it is that it is computationally simple, allowing it to perform real-time analysis of the image.

The local two-valued pattern eigenvector can be computed in the following way:
1. Cut the detection window into blocks (cells, for example, 16x16 pixels per block).
2. For each pixel in the block, compare it with its eight neighboring pixels (upper left, Zozhong, lower left, right upper). You can compare them in a clockwise or counterclockwise order.
3. Set to 1 for a central pixel greater than a neighborhood, otherwise, set to 0. This obtains a 8-bit binary number (typically converted to decimal digits) as a feature of that location.
4. Compute histograms for each block.
5. At this point, you can choose to normalized the histogram;
6. The histogram of all blocks is concatenated, which obtains the eigenvector of the current detection window.

For each pixel in the image, the gray value of the pixel is transformed into a eight-bit binary sequence by calculating the size relation of each pixel and the central pixel in the 3*3 neighborhood. The specific calculation process as shown in the following figure, for the image of any point IC, the LBP features are calculated as the center of IC, and the 8 points adjacent to IC are taken as I0,i1,..., I7 according to the clockwise direction; the pixel value of the IC point is the threshold and if the pixel value of the II point is less than the IC, then II is converted to 0 , or 1, the two-valued 0 and 1 sequences are considered as a 8-bit binary number, and the value of the LBP operator at the IC point can be obtained by converting the binary number to decimal.
The basic LBP operator is limited to the neighborhood of 3*3, and the large scale structure of large image can not extract the required texture feature well, so the researchers have extended the LBP operator. The new LBP operator LBP (P,R) can compute the eigenvalues of different radius neighborhood sizes and different pixel points, where P represents the number of pixels around, R represents the neighborhood radius, while the original Square neighborhood is extended to the circle, the following figure gives four kinds of extended LBP examples, where r can be decimal, For a point that does not fall to the integer position, according to the pixel gray value of the nearest two integer position in the orbit, we can calculate its gray value by using the method of bilinear difference value.


LBP (P,R) has a 2^p value, that is, the image has a 2^p binary model, however, the actual study found that all modes of expression of information is different in importance, statistical studies show that a few patterns in a particular image concentration, to achieve the total pattern of about 90% of the proportion, Ojala and other people define this mode as uniform mode, if a binary sequence as a circle, 0-1 and 1-0 of the total number of changes occur in the sum of not more than two times, then this sequence is uniform mode, such as 00000000, 00011110, 00100001, 11111111, when using LBP to express image textures, usually only care about uniform mode, and all other patterns are grouped into the same class.

The LBP operator quantifies the point by using the relation between the point and the point. After quantization, the effect of illumination on image can be eliminated more effectively. As long as the illumination changes are not enough to change the size relationship between the two pixel values, the value of the LBP operator will not change, so to some extent, the algorithm based on LBP solves the problem of illumination change, but when the illumination varies unevenly, the size relationship between the pixels is destroyed, The corresponding LBP pattern has also changed.


void Elbp (mat& src, Mat &dst, int radius, int neighbors) {for (int n = 0; n < neighbors; n++) {//Calculation of sampling points
		float x = static_cast<float> (-radius * sin (2.0*cv_pi*n/static_cast<float> (neighbors)));
		Float y = static_cast<float> (radius * cos (2.0*cv_pi*n/static_cast<float> (neighbors)));
		Upper rounding and rounding value int fx = static_cast<int> (floor (x));
		int fy = static_cast<int> (Floor (y));
		int cx = static_cast<int> (ceil (x));
		int cy = static_cast<int> (ceil (y));
		Small number part float ty = y-fy;
		float tx = X-FX;
		Set interpolation weights float w1 = (1-tx) * (1-ty);
		float W2 = tx * (1-ty);
		float W3 = (1-tx) * TY;
		float W4 = tx * TY; Looping image data for (int i = radius; i < Src.rows-radius i++) {for (int j = radius; j < Src.cols-radius; j+ +) {//compute interpolation float t = static_cast<float> (w1*src.at<uchar> (i + FY, j + FX) + w2*src.at<uchar> (i + FY, j + cx) + w3*src.at<uchar> (i + CY, j + FX) + w4*src.at<uchar> (i + CY, J + CX)); Encode dst.at<uchar> (I-radius, J-radius) + + (T > src.at<uchar> (i, j)) | | (Std::abs (T-src.at<uchar> (i, J)) < Std::numeric_limits<float>::epsilon ()))
			<< N; }} void Elbp1 (mat& src, Mat &dst) {//cyclic processing of image data for (int i = 1; i < src.rows-1; i++) {for T j = 1; J < Src.cols-1;
			J + +) {Uchar tt = 0;
			int tt1 = 0;
			Uchar u = src.at<uchar> (i, j);
			if (src.at<uchar> (i-1, j-1) >u) {TT + 1 << tt1;}
			tt1++;
			if (Src.at<uchar> (I-1, J) >u) {TT + 1 << tt1;}
			tt1++;
			if (Src.at<uchar> (i-1, J + 1) > U) {tt = 1 << tt1;}
			tt1++;
			if (Src.at<uchar> (i, J + 1) > U) {tt = 1 << tt1;}
			tt1++;
			if (src.at<uchar> (i + 1, j + 1) > U) {tt = 1 << tt1;}
			tt1++;
			if (src.at<uchar> (i + 1, j) > U) {tt = 1 << tt1;}
			tt1++; If (Src.at<uchar> (i + 1, j-1) > U)
			{TT + 1 << tt1;}
			tt1++;
			if (Src.at<uchar> (I-1, J) > U) {tt + 1 << tt1;}

			tt1++;
		Dst.at<uchar> (i-1, j-1) = TT; }
	}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.