HoG feature vector confusion I am new in the machine learning world and currently I am working on Computer Vision project. I am confused about HoG feature vector. In my understanding, the feature vector should contain magnitude and orientation of gradients. The gradient is a vector of partial derivations $v = \{ \frac{\partial F}{\partial x}, \frac{\partial F}{\partial y} \}$. We are supposed to calculate this gradient for every pixel in the image.
My question is: What gradient do we take? As I understand it, we are supposed to take gradient and its orientation/magnitude, where the biggest change occurs (in shade / color). But what about image like this?

If we say the white dot is just one pixel, every direction of magnitude has same "scene change" from white to black, how do we chose gradient then?
Secondly, how are we supposed to take the magnitude of gradient? Lets say we have this image:

If we take 1st pixel (top left) and look for its gradient, the only scene change stats in the middle of image. Do we say the orientation is 0° and magnitude 50px (let's say it's a 100x100 image)?
Or how do we deal with this?
Thanks for answers.
 A: It is fairly simple. Since the computer images are discrete, we use some approximations to compute gradients. The method to compute the gradients in discrete computer images is called finite differences. Usually, we take the forward finite difference1, meaning the gradient $\frac{\partial F}{\partial x}$ in a pixel at coordinates [a,b] is computed as:
$$\frac{\partial F(a,b)}{\partial x} = F(a+1,b)-F(a,b).$$
Analogously, 
$$\frac{\partial F(a,b)}{\partial y} = F(a,b+1)-F(a,b).$$
So you simply compute the difference between intensities in the neighboring two pixels. You repeat this for every pixel in the image (except for the right and bottom edge, where no more neighboring pixels are; here we define the gradient to be zero), so the output feature map has the same size as the original image.
To answer your two examples:


*

*In the first picture, the gradient will be zero everywhere except for the pixel above the dot (there it will be $[0,1]$), pixel left to the dot ($[1,0]$), and the dot itself ($[-1,-1]$).

*In the second picture, the gradient will be zero everywhere except for the rightmost black pixels (gradient will be $[1,0]$).



1 Other variants are backward differences and central differences.
