HOG is an method to create a Feature Descriptor used in computer vision for object detection.
How HOG Feature is extracted????
Histogram of oriented gradients which is called as HOG is Extracted by the below steps.
STEP 1:
We will take the actual image , in our example we have this one image.
Then we will take a patch of image from the image.
We will resize the image to 1:2 which is 64x128
Then the image is divided into 8x16 grids.
After dividing, each grid contains a pixel values of 8x8
STEP 2:
Now for each pixel position, gradient Magnitude and gradient orientation is founded.
For Example, If you have to find the pixel value for the 90,then all the surroundings values of 90 is taken.
Then all the diagonal values will get neglected.
At the next step we will calculate the Difference in x and Difference in y
STEP 3:
We will create a new 8x8 magnitude cells and a 8x8 orientation cells,and we will find the position of the pixel value and put the magnitude and orientation in the new cell in the position of the pixel value.
Similarily,we will find the the magnitude and orientation for every pixel values.And finally we will have a 8x8 values of magnitude and 8x8 values of orientation.
STEP 5:
By using the orientation and the magnitude,we will draw an histogram.This histogram have 9 bins starting from 0-160.Note that we may choose different bins,in this example , i am choosing 9 bins.This histogram contains the orientation the X-AXis and the magnitude in the Y-AXis.
If we have to draw an histogram for orientation 60 ,then we will draw an magnitude value of 97 in the 60 degree bin. Similiarly, we will put every value in the magnitude box into the corresponding orientation value. This will repeat for every orientation value. Finally we will have a histogram which contains all the orientations and magnitude values.
STEP 7:
In this step, we will have a feature vector of size 9 (size of bins).
In this step, we will have a feature vector of size 9 (size of bins).
For Example we will have a feature vector like [345,456,123,89,34,23,567,890,321].
This values are the magnitude values corresponding to the orientation values starting from 0 to 160.
0->345
20 -> 456
40 -> 123
60 -> 89
80 -> 34
100 -> 23
120 -> 567
140 -> 890
160 -> 321
STEP 8 :
Then , a Pictorial representation of the feature vector is drawn.
Here the length of each arrow is equal to the magnitude of the corresponding orientations . For Example , the length of 0 degree is equal to the magnitude value 345.
STEP 9:
Now we have completed the methods of feature extraction for one grid . Next we will repeat these steps for every grid in the photo. And each grid will have a feature vector of size 9.
STEP 10:
Now we will divide the grids by blocks. Each block contains Four cells. Each cell have a feature vector of size 9.
STEP 11:
At the end of each row ,the block starts form the next row ,until the last row and the last column.
STEP 13:
Now we concatenate the feature vectors, in the first block to form a combined feature vector of size 36 (9 x 9x 9 x 9), and the normalize the values.
We repeat this concatenation for every block and normalize it.
After doing this normalization for every block, we will have an output which contains the HOG features of an image.