Ask Your Question
2

Features extraction via LBP with other classifiers

asked 2014-04-08 05:27:15 -0600

UncleSam gravatar image

updated 2014-04-08 05:49:45 -0600

berak gravatar image

Hi everybody!

Is it possible to extract features with a LBP model in order to get a classification with other methods? I'd like to extract the lbp features from an image and classify them with KNN and SVM, how can I do that?

thanks for any type of help.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2014-04-09 04:27:57 -0600

You can use LBP implementation from here. It is for OpenCV with uniform patterns, new OpenCV's interface, and has good computational performance. Hope this help.

edit flag offensive delete link more

Comments

fantastic! thanks a lot!

UncleSam gravatar imageUncleSam ( 2014-04-17 10:55:47 -0600 )edit
2

answered 2014-04-08 05:45:56 -0600

berak gravatar image

updated 2014-04-08 05:47:33 -0600

lbp is basically this:

you got a pixel , and it's neighbours:

   7 0 1
   6 P 2
   5 4 3

then you walk in a circle around the neighbours, and set a result bit, if the neighbour is larger than the center pixel.

uchar lbp(const Mat_<uchar> & img, int x, int y)
{
    uchar v = 0;
    uchar c = img(y,x);
    v += (img(y-1,x  ) > c) << 0;
    v += (img(y-1,x+1) > c) << 1;
    v += (img(y  ,x+1) > c) << 2;
    v += (img(y+1,x+1) > c) << 3;
    v += (img(y+1,x  ) > c) << 4;
    v += (img(y+1,x-1) > c) << 5;
    v += (img(y  ,x-1) > c) << 6;
    v += (img(y-1,x-1) > c) << 7;
    return v;
}

it does not matter, where you start, or in which direction you walk, as long as you keep consistency there.

but usually, those features are not used 'as is'. i.e if you want to do some kind of 'textron-matching', you'd chop up your image into patches

  ----------
  |  |  |  |
  ----------
  |  |  |  |
  ----------
  |  |  |  |
  ----------

for each patch (3x3 here), make a histogram of lbp-features(1x256) (that's the H in LBPH), concat those to a flat 1d array(1x2304), and use this as feature vector for further classification (svm knn, or the like)

edit flag offensive delete link more

Comments

so you're telling me there's no implementation in opencv for such extraction right?!

UncleSam gravatar imageUncleSam ( 2014-04-08 05:54:18 -0600 )edit
1

unsure if i understand you right. there's an implementation in the faceregonition/contrib module, and another one in cascade_training (for the obvious lbp-cascade) .

none of them are used with svm in opencv, so if that's your goal, you have to roll your own.

oh, now i get it. -

unfortunately both implementations are encapsulated/private/static, so you can't easily access or reuse the code for your own classification.

berak gravatar imageberak ( 2014-04-08 06:00:33 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2014-04-08 05:27:15 -0600

Seen: 3,408 times

Last updated: Apr 09 '14