A
A
Andrei1penguin12020-11-09 11:41:44
Machine learning
Andrei1penguin1, 2020-11-09 11:41:44

Am I counting the histogram of gradients correctly?

Good day, I didn’t find a clear description of the HOG algorithm, in many articles only vague ideas are given, in this regard, I had to think of something myself and I want to ask if I’m doing it right or not.
Specifically, I’m not sure about the calculation histograms for an 8×8 cell
Suppose we have an 8×8 matrix:

10 20 30 40 50 60 70 80
15 25 35 45 55 65 75 85
90 100 110 120 130 140 150 160 95
105 115 125 135 145
230 220 210 200 190 180
255 245 235 225 215 205 195 185
170 160 150 140 130 120 110 100
175 165 155 145 135 125

115
105
Since the direction in x and y for pixels in the center, for example for pixel 2 columns 3 rows (100) will be the following:
In x: |90-110| = 20
By y: |25-105| = 80
But how to calculate the directions, for example, for a pixel of the 1st row of the 1st column (10)
I think that this should be considered as a half-difference with the only neighboring pixels, that is, like this:
By x: |(10-20)/ 2|=5
By y: |(10-15)/2|=2.5

And the second moment I don't understand:
When we calculate the magnitude and orientation for each pixel using formulas:

Magnitude = √x^2+y^2 = √25+ 6.25
=

.

0 20 40 60 80 100 120 140 160

And I'm not sure about the following points:
1. Suppose in the course of calculations we find out that we have two angles in 8 × 8 cells, equal to, for example, 140:
Then we have values ​​corresponding to magnitude pixels to which the values ​​of orientation 140 belong, and such pixels, as we assumed, 2, do we summarize?
That is, if in the 8 × 8 histogram we have one pixel with magnitude 48 and orientation 140 and the second pixel with magnitude 142 and orientation also 140, then in field 140 of the 9 × 1 vector we enter the sum of the values ​​48 + 142 = 190?

2. If the orientation of a pixel is exactly between two cells, for example, there is a pixel with magnitude 72 and orientation 50, then in the cells between which this angle is located (that is, in the cells corresponding to angles 40 and 60), we enter exactly half of the magnitude value of this pixel 36? (72/2=36)

3. And referring to point 2, it turns out that if the orientation value of the pixel is not very convenient, for example 135, then the values ​​​​in the nearest cells of the 9 × 1 vector (120 and 140) are entered in proportion to which cell's orientation value is closer?
That is, let's say we have a pixel with magnitude 20 and orientation 135, then the distribution proportion will be as follows:
1/4 to cell 120, that is, 20/4 = 5
3/4 to cell 140, that is, 20/4 * 3 = 15
And the value 5 will fall into cell 120, and the value 15 will fall into cell 140

Please tell me if I'm doing it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmshar, 2020-11-09
@dmshar

A histogram - by definition - is a data structure (object) in which each line corresponds to a certain interval of possible values ​​​​of your input data, and the value in this line is the number of elements in the input data, the value that falls within this interval.
So your reasoning is correct.
At the same time, no "uncomfortable elements" are divided into any parts.
(I will not copy my answer on the third resource).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question