A method for producing a histogram of oriented gradients, HOG, for at least a portion of an image comprising: dividing the portion of an input image into a plurality of cells, each cell comprising a plurality of image pixels; for each cell of said cells determining a histogram of accumulated gradient directions by: for each image pixel of a cell, calculating the horizontal, gx, and vertical, gy, components of the gradient vector; performing the following tests: (i) gx>0; (ii) gy>0; (iii) |gx|>|gy|; (iv) |gx|>2|gy| OR |gy|>2|gx|; and (v) |gx|>4|gy| OR |gy|>4|gx|; and wherein in iv) and v) the values of 2lgxl, 2lgyl, 4lgxl, and 4lgyl are calculated by bit-shift operations; combining the result of said tests into a binary mask; comparing the mask to predetermined mask values to determine a sector of gradient directions comprising the gradient vector, the predetermined mask values being associated with a unique sector of gradient directions, the association being such that gradients in the associated sector are those gradients that have as outcome of the above tests the associated mask; determining a set of histogram bins that is associated to the sector according to a predetermined relation between sectors and bins; accumulating the gradient magnitude, or an approximation thereof, in all bins of said set of histogram bins. dividing the portion of an input image into a plurality of cells, each cell comprising a plurality of image pixels; for each cell of said cells determining a histogram of accumulated gradient directions by: for each image pixel of a cell, calculating the horizontal, gx, and vertical, gy, components of the gradient vector; performing the following tests: (i) gx>0; (ii) gy>0; (iii) |gx|>|gy|; (iv) |gx|>2|gy| OR |gy|>2|gx|; and (v) |gx|>4|gy| OR |gy|>4|gx|; and wherein in iv) and v) the values of 2lgxl, 2lgyl, 4lgxl, and 4lgyl are calculated by bit-shift operations; combining the result of said tests into a binary mask; comparing the mask to predetermined mask values to determine a sector of gradient directions comprising the gradient vector, the predetermined mask values being associated with a unique sector of gradient directions, the association being such that gradients in the associated sector are those gradients that have as outcome of the above tests the associated mask; determining a set of histogram bins that is associated to the sector according to a predetermined relation between sectors and bins; accumulating the gradient magnitude, or an approximation thereof, in all bins of said set of histogram bins. for each image pixel of a cell, calculating the horizontal, gx, and vertical, gy, components of the gradient vector; performing the following tests: (i) gx>0; (ii) gy>0; (iii) |gx|>|gy|; (iv) |gx|>2|gy| OR |gy|>2|gx|; and (v) |gx|>4|gy| OR |gy|>4|gx|; and wherein in iv) and v) the values of 2lgxl, 2lgyl, 4lgxl, and 4lgyl are calculated by bit-shift operations; combining the result of said tests into a binary mask; comparing the mask to predetermined mask values to determine a sector of gradient directions comprising the gradient vector, the predetermined mask values being associated with a unique sector of gradient directions, the association being such that gradients in the associated sector are those gradients that have as outcome of the above tests the associated mask; determining a set of histogram bins that is associated to the sector according to a predetermined relation between sectors and bins; accumulating the gradient magnitude, or an approximation thereof, in all bins of said set of histogram bins. calculating the horizontal, gx, and vertical, gy, components of the gradient vector; performing the following tests: (i) gx>0; (ii) gy>0; (iii) |gx|>|gy|; (iv) |gx|>2|gy| OR |gy|>2|gx|; and (v) |gx|>4|gy| OR |gy|>4|gx|; and (i) gx>0; (ii) gy>0; (iii) |gx|>|gy|; (iv) |gx|>2|gy| OR |gy|>2|gx|; and (v) |gx|>4|gy| OR |gy|>4|gx|; and wherein in iv) and v) the values of 2lgxl, 2lgyl, 4lgxl, and 4lgyl are calculated by bit-shift operations; combining the result of said tests into a binary mask; comparing the mask to predetermined mask values to determine a sector of gradient directions comprising the gradient vector, the predetermined mask values being associated with a unique sector of gradient directions, the association being such that gradients in the associated sector are those gradients that have as outcome of the above tests the associated mask; determining a set of histogram bins that is associated to the sector according to a predetermined relation between sectors and bins; accumulating the gradient magnitude, or an approximation thereof, in all bins of said set of histogram bins.