# Viola-Jones algorithm: Haar-like features, how are the features extracted?

If I have an image like this

1 2 3 4 5 6 7 8
a b c d e f g h
...


And I apply a Haar-like feature with a template

1 1 1 1
-1 -1 -1 -1


Then in the first position we get X1 = 1+2+3+4+a+b+c+d. If we slide one side to the right, we again get X2 = 2+3+4+5+b+c+d+e.

This way we will get X1 and X2 and X3 and so on. Now, how are these values combined to get the feature? Because when we say a feature we are not just running that template in one place, rather we will run it over multiple places in the image. It gives lots of values like X1,X2 and X3 and so on. Now, how are those combined to get the final feature which will be passed to Adaboost?

In summary, each feature is used to train it's own classifier. So in your example, the calculated features X1, X2, ... Xn you describe coorespond to apply some set of feature transforms f_1, f_2, ... f_n to a single image. This is a bit backwards from what actually happens. What the method really does is train a classifier for each feature. So if you had n features, you would have n classifiers. Then in an adaboost fashion, you upweight the classifier that performed the best. I.e, you are upweighting the classifier based soley on th best performing feature. You then repeat and re-weight all the classifiers until you reach convergence.
• Sorry if this is stupid thing to ask - but in your answer when you say there are X1,...Xn the n features - they are coming from the same Haar featuretemplate shown in example in the question right? So when are we using the all of the haar feature templates? (Btw +1 for your effort in answering my bad question maybe) – user27286 Apr 10 at 18:45
• Nah, no stupid questions! Only stupid answers on my part. More concretely, each haar feature template would be used to create a single classifier. So if you have n haar feature templates you have n classifiers. For each of those n classifiers, you train the entire image set and use adaboost to come to a final solution. – juicedatom Apr 10 at 19:41
• I have n haar feature templates. So for example, one template is as shown in my question. Now if I slide this feature template over an image I will get many scalar values due to different location on which it is slid over. All I am asking this, what would I do with all these values? Do I just put them a vector and tell that it is my feature corresponding to the feature template? Also just notice, in my question I said 'X1 is the output of running this feature templated in one location. X2 is the output of running the same feature template over different position.You define X1` otherway. – user27286 Apr 10 at 19:54