Ask Your Question
2

How to visualize the 32 dimension HOG from DPM?

asked 2016-12-20 09:27:36 -0600

TanaseC gravatar image

updated 2016-12-20 20:38:31 -0600

Hello,

I'm relatively new to programming in OpenCV and to the image processing gig so please bear with me. I'm working on my master thesis and I'm trying to find a way to visualize the HOG that I get from the Feature::computeHOG32D function in the DPM opencv_contrib. I have two problems:

  • There is an inconsistency regarding the function parameters and the output HOG
  • How do I interpret the values inside the 32 D descriptor? What angle is associated with what bin/position? What does the weighted vote mean? Is there some kind of range for it

    Regarding my first problem, I read how the process should work, namely:

  • 8*8 cell of pixels

  • 9 bins representing angles from 0 to 180. These are filled with values representing light intensity.
  • 4 cells are grouped into 1 block and concatenated into a final descriptor
  • 9 bins * 4 cells = 36 dimension descriptor.

The parameters in the function are a bit different:

  • Cell size is fed from the model. Usually stays the same. 8*8.
  • numOrient is set to 18. So there are 18 orientations, aka 18 bins, right?
  • I assume cells are still grouped together by 4.
  • Each cell has a size of 32 instead of 9. Which doesn't make much sense to me. (Note: I think maybe some of them are contrast-insensitive features and some are contrast-sensitive but that still doesn't explain why the size is 32 and not 36.)

Regarding the second one, I'm thinking of drawing lines at certain angles and based on the weighted vote I'm going to increase the light intensity. The problems I'm thinking of are:

  • I assume the position at a value is the value of a specific bin, an orientation, but I don't know which one.
  • I also don't know if it's in radians or not.
  • I don't know what the weighted vote value means. I need a range or a way to appreciate it.

I'm sorry If I made any mistake please inform me and I will correct it.

Thank you for your time!

edit retag flag offensive close merge delete

Comments

AFAIK there is no built-in HOG visualization tool in OpenCV.

Once I built one, which was no more than drawing lines with the angles obtained in the bins and center on the corresponding cell. Shouldn't be too hard.

Pedro Batista gravatar imagePedro Batista ( 2016-12-20 11:09:46 -0600 )edit

Did you build one for this particular function output? I built one myself in Matlab but the HOG was also made by me so, of course, I knew what the values in the data structure were. That's the problem here, I need to know how to interpret the values.

TanaseC gravatar imageTanaseC ( 2016-12-20 20:11:23 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2016-12-21 06:02:35 -0600

updated 2016-12-21 06:30:53 -0600

If you want to create a visualization for HOG you'll need to understand what is it that you are calculating with HOG.

In HOG, you evaluate blocks that are subdivided into cells of pixels. In your case, you have 8x8 pixel cells and 32x32 blocks. So, your block has 4x4 cells. Look at the image bellow to better understand what I am talking about.

image description

So, HOG is all about evaluating edges of images. Generically, a local HOG feature is computed inside one cell and has two components, gradient (G), which is a measure of strength of an edge, and orientation (theta), that you refer to as "bin". This bin is a way to simplify the feature. So, instead of each feature being able to assume any angle, it can only assume 18 (in your case) bins. Each bin interval is of 20 degrees (360 / 18) so, if the angle is, for example, 30, this means it fell into bin 2.

   //-- pseudo-code
    if (0 < angle < 20)
       bin = 1;
    else if (20 < angle < 40)
       bin = 2;
    ....

image description

(Ix and Iy are the intensity of the pixel in the horizontal and vertical gradient images)

So, in your case each block will be described by 16 (4x4 cells) features, each of these features is represented by a gradient and an orientation. To visualize this, just draw lines in the centre of each block, the line growing with gradient, and the orientation of the line is set by the bin, so that there can only be 18 different orientations. See image bellow for an example.

image description

Summing up, for each block you will draw 16 lines with different sizes and orientations depending to the gradient and orientation. Keep in mind that the gradients need to be normalized to fit in the blocks.

Hope this helps, good luck.

ADDED BY @StevenPuttemans

To complete this nice explanation of Pedro, I have written code to visualize HOG features exactly like this, based on some earlier work of Jurgen Brauer, which is no longer foundable on the net ...

// HOGDescriptor visual_image analyzing
// Adapted from http://www.juergenwiki.de/work/wiki/doku.php?id=public%3ahog_descriptor_computation_and_visualization
// ONLY PRECAUSIONS ARE
// --> Image size width/heigth needs to be a multiple of block width/heigth
// --> Block size width/heigth (multiple cells) needs to be a multiple of cell size (histogram region) width/heigth
// --> Block stride needs to be a multiple of a cell size, however current code only allows to use a block stride = cell size!
// --> ScaleFactor enlarges the image patch to make it visible (e.g. a patch of 50x50 could have a factor 10 to be visible at scale 500x500 for inspection)
// --> viz_factor enlarges the maximum size of the maximal gradient length for normalization. At viz_factor = 1 it results in a length = half the cell width
Mat get_hogdescriptor_visual_image(Mat& origImg, vector<float>& descriptorValues, Size winSize, Size cellSize, int scaleFactor, double viz_factor)
{
    Mat visual_image;
    resize(origImg, visual_image, Size(origImg.cols*scaleFactor, origImg.rows*scaleFactor));

    int gradientBinSize = 9;
    float radRangeForOneBin = 3.14/(float)gradientBinSize; // dividing ...
(more)
edit flag offensive delete link more

Comments

2

Nice edit @StevenPuttemans :)

Cheers!

Pedro Batista gravatar imagePedro Batista ( 2016-12-21 06:36:45 -0600 )edit

You welcome!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-12-22 03:13:17 -0600 )edit

in my case I have HOGDescriptor d1(Size(512, 512), Size(16, 16), Size(16, 16), Size(16, 16), 9); by calling

Mat r1 = get_hogdescriptor_visual_image(r_img1_gray, descriptorsValues1, Size(512, 512),        Size(16,16),1,1.0);

i got visualization freeze

peter_cz gravatar imagepeter_cz ( 2017-09-09 18:34:41 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-12-20 09:27:36 -0600

Seen: 2,339 times

Last updated: Dec 21 '16