OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Fri, 30 May 2014 04:12:09 -0500Local Binary Pattern model in FaceRecognizerhttp://answers.opencv.org/question/3277/local-binary-pattern-model-in-facerecognizer/In which way does LBPH FaceRecognizer combine in his model information from differents training images?
Thu, 18 Oct 2012 08:23:04 -0500http://answers.opencv.org/question/3277/local-binary-pattern-model-in-facerecognizer/Answer by simone for <p>In which way does LBPH FaceRecognizer combine in his model information from differents training images?</p>
http://answers.opencv.org/question/3277/local-binary-pattern-model-in-facerecognizer/?answer=3440#post-id-3440Thank you very much, this remove my dobut!Wed, 24 Oct 2012 08:42:33 -0500http://answers.opencv.org/question/3277/local-binary-pattern-model-in-facerecognizer/?answer=3440#post-id-3440Answer by Philipp Wagner for <p>In which way does LBPH FaceRecognizer combine in his model information from differents training images?</p>
http://answers.opencv.org/question/3277/local-binary-pattern-model-in-facerecognizer/?answer=3296#post-id-3296Face Recognition involves two crucial aspects: (1) extracting relevant facial features and (2) classifier design. Local Binary Patterns (LBP) have proven to yield highly discriminative features, while being computationally simple and robust against monotonic grayscale transformations. You can read up the original publication at:
* T. Ahonen, A. Hadid, and M. Pietikäinen, *"Face recognition with local binary patterns"* in Proc. Euro. Conf. Comput. Vis., 2004, pp. 469–481. \[[PDF Online Available Here](http://masters.donntu.edu.ua/2011/frt/dyrul/library/article8.pdf)\].
The basic idea of LBP is to summarize the local structure in an image by comparing each pixel with its neighborhood. Take a pixel as center and threshold its neighbors against. If the intensity of the center pixel is greater-equal its neighbor, then denote it with 1 and 0 if not. You'll end up with a binary number for each pixel, just like 11001111. It's easy to see, that this leads to 2^8 possible combinations, which are called Local Binary Patterns or sometimes LBP codes. The first LBP operator actually used a fixed 3 x 3 neighborhood just like this:
![image description](/upfiles/13505958799667518.png)
And here's how to calculate them with OpenCV2:
template <typename _Tp>
void OLBP_(const Mat& src, Mat& dst) {
dst = Mat::zeros(src.rows-2, src.cols-2, CV_8UC1);
for(int i=1;i<src.rows-1;i++) {
for(int j=1;j<src.cols-1;j++) {
_Tp center = src.at<_Tp>(i,j);
unsigned char code = 0;
code |= (src.at<_Tp>(i-1,j-1) > center) << 7;
code |= (src.at<_Tp>(i-1,j) > center) << 6;
code |= (src.at<_Tp>(i-1,j+1) > center) << 5;
code |= (src.at<_Tp>(i,j+1) > center) << 4;
code |= (src.at<_Tp>(i+1,j+1) > center) << 3;
code |= (src.at<_Tp>(i+1,j) > center) << 2;
code |= (src.at<_Tp>(i+1,j-1) > center) << 1;
code |= (src.at<_Tp>(i,j-1) > center) << 0;
dst.at<unsigned char>(i-1,j-1) = code;
}
}
}
For more details on the computation and LBP-variants, please see:
* [Face Recognition with OpenCV: Local Binary Patterns Histograms](http://docs.opencv.org/trunk/modules/contrib/doc/facerec/facerec_tutorial.html#local-binary-patterns-histograms)
Now a face can be regarded as a composition of those micro-patterns, hence we build a histogram to get the distribution. But if you throw all LBP into a single histogram all spatial information is discarded. In tasks like face detection (and a lot of other pattern recognition problems) spatial information is very useful, so it has to be incorporated into the histogram somehow. The representation proposed by Ahonen et al. in *Face Recognition with Local Binary Patterns is to divide the LBP image into grids and build a histogram of each cell seperately. Then by concatenating the histograms the spatial information is encoded (not merging them). A classification between those spatially enhanced histograms can then be performed by using a Nearest Neighbor classifier with a histogram distance, e.g. Chi-Square.
So when to choose Local Binary Patterns Histograms over Eigenfaces and Fisherfaces? Eigenfaces and Fisherfaces estimate a model based on the variance in your training data, so they perform very bad if given only few samples (you can read that up in various publications). Since a face recognition with Local Binary Patterns Histograms does not build a model explicitly, it doesn't suffer from small sample size problems.
By the way you can find an interesting LBP-variant on the [face.com](http://www.face.com) research page:
* Lior Wolf, Tal Hassner, and Yaniv Taigman. *"Descriptor Based Methods in the Wild"* in European Conference on Computer Vision (ECCV) workshop on Faces in Real-Life Images: Detection, Alignment, and Recognition, 2008. \[[PDF Online Available Here](http://face.com/research/index.php?page=publications.html)\].Thu, 18 Oct 2012 16:33:07 -0500http://answers.opencv.org/question/3277/local-binary-pattern-model-in-facerecognizer/?answer=3296#post-id-3296Comment by Haris for <div class="snippet"><p>Face Recognition involves two crucial aspects: (1) extracting relevant facial features and (2) classifier design. Local Binary Patterns (LBP) have proven to yield highly discriminative features, while being computationally simple and robust against monotonic grayscale transformations. You can read up the original publication at:</p>
<ul>
<li>T. Ahonen, A. Hadid, and M. Pietikäinen, <em>"Face recognition with local binary patterns"</em> in Proc. Euro. Conf. Comput. Vis., 2004, pp. 469–481. [<a href="http://masters.donntu.edu.ua/2011/frt/dyrul/library/article8.pdf">PDF Online Available Here</a>].</li>
</ul>
<p>The basic idea of LBP is to summarize the local structure in an image by comparing each pixel with its neighborhood. Take a pixel as center and threshold its neighbors against. If the intensity of the center pixel is greater-equal its neighbor, then denote it with 1 and 0 if not. You'll end up with a binary number for each pixel, just like 11001111. It's easy to see, that this leads to 2^8 possible combinations, which are called Local Binary Patterns or sometimes LBP codes. The first LBP operator actually used a fixed 3 x 3 neighborhood just like this: </p>
<p><img alt="image description" src="/upfiles/13505958799667518.png"></p>
<p>And here's how to calculate them with OpenCV2:</p>
<pre><code>template <typename _Tp>
void OLBP_(const Mat& src, Mat& dst) {
dst = Mat::zeros(src.rows-2, src.cols-2, CV_8UC1);
for(int i=1;i<src.rows-1;i++) {
for(int j=1;j<src.cols-1;j++) {
_Tp center = src.at<_Tp>(i,j);
unsigned char code = 0;
code |= (src.at<_Tp>(i-1,j-1) > center) << 7;
code |= (src.at<_Tp>(i-1,j) > center) << 6;
code |= (src.at<_Tp>(i-1,j+1) > center) << 5;
code |= (src.at<_Tp>(i,j+1) > center) << 4;
code |= (src.at<_Tp>(i+1,j+1) > center) << 3;
code |= (src.at<_Tp>(i+1,j) > center) << 2;
code |= (src.at<_Tp>(i+1,j-1) > center) << 1;
code |= (src.at<_Tp>(i,j-1) > center) << 0;
dst.at<unsigned char>(i-1,j-1) = code;
}
}
}
</code></pre>
<p>For more details on the computation and LBP-variants, please see:</p>
<ul>
<li><a href="http://docs.opencv.org/trunk/modules/contrib/doc/facerec/facerec_tutorial.html#local-binary-patterns-histograms">Face Recognition with OpenCV: Local Binary Patterns Histograms</a></li>
</ul>
<p>Now a face can be regarded as a composition of those micro-patterns, hence we build a histogram to get the distribution. But if you throw all LBP into a single histogram all spatial information is discarded. In tasks like face detection (and a lot of other pattern recognition problems) spatial information is very useful, so it has to be incorporated into the histogram somehow. The representation proposed by Ahonen et al. in *Face Recognition with Local Binary Patterns is to divide the LBP image into grids and build a histogram of each cell seperately. Then by concatenating the histograms the spatial information is encoded (not merging them). A classification between those spatially enhanced histograms can then be performed by using a Nearest Neighbor classifier with a histogram distance, e.g. Chi-Square.</p>
<p>So when to choose Local Binary Patterns Histograms over Eigenfaces and Fisherfaces? Eigenfaces and Fisherfaces estimate a model based on the variance in your training data, so they perform very bad if given only few samples (you can read that up in various publications). Since a ...<span class="expander"> <a>(more)</a></span></p></div>http://answers.opencv.org/question/3277/local-binary-pattern-model-in-facerecognizer/?comment=34336#post-id-34336Nice answer......Fri, 30 May 2014 04:12:09 -0500http://answers.opencv.org/question/3277/local-binary-pattern-model-in-facerecognizer/?comment=34336#post-id-34336Answer by raqghu for <p>In which way does LBPH FaceRecognizer combine in his model information from differents training images?</p>
http://answers.opencv.org/question/3277/local-binary-pattern-model-in-facerecognizer/?answer=29735#post-id-29735can lbp recognise faces eventhough there is a change in position of features ie eyes,nose etcMon, 10 Mar 2014 10:58:45 -0500http://answers.opencv.org/question/3277/local-binary-pattern-model-in-facerecognizer/?answer=29735#post-id-29735