Finished writing some of the code for HoG features. Still haven't completely understood/implemented the portion for detection via sliding window.
Gradient maps are first computed using Sobel operator or 1-D derivative masks.
|
gradient in x-direction |
|
gradient in y-direction |
Using these gradient maps, we can calculate a magnitude and orientation for every pixel. We bin these pixels based on the angle of orientation, using nine bins (increments of 20 degrees, 0 to 180).
Then we group pixels together into "cells" and the orientation of the cell is determined by the magnitudes of the pixels within that cell. Here are some visual representations of HoG features of an image.
The bin with the highest magnitude for each cell is chosen to represent that cell:
|
Original image |
|
16x16 pixel cells |
|
8x8 pixel cells |
|
4x4 pixel cells |
Here are some more examples (original on left, HoG on right)
In recent years, a lot of people have reached out to me for guidance on how to generate these HOG visualizations. Please take a look at https://github.com/Porkbutts/Vespidae-Wasp-Classification/blob/master/Project/practice.cpp#L223 if you are interested.
Hey Adrian
ReplyDeleteCan u please give me the code for visualizing the hog in matlab , i m able to get the hogdescripter value , but dont know how to convert them into image for visualizing the features.
Thanks a lot for the help.
Hi crawler,
DeleteUnfortunately the code I have is in C++ and I haven't looked at it since this project.
What you need to do is take a look at the HOG descriptor, which should just be a collection of orientations and magnitudes. Then you can simply create your own image from it (like I did). You can use lines and simply scale their length by the magnitude, and then rotate them according to the orientation. Let me know if that helps.
hi adrian
Deletecan you please give e the code for visualizing hog in c++ ?
The repo is located here: https://github.com/Porkbutts/Vespidae-Wasp-Classification/tree/master/Project
DeletePlease take a look at drawHog function in practice.cpp/h
Deletethank you very much ! i will take a look ,
please have you an idea how to draw histogram in c++ (with direction and magnitude)
please , can u give me the code for visualizing the hog in c++ ?
ReplyDelete