Documentation>C API
hog.c File Reference

Histogram of Oriented Gradients (HOG) - Definition. More...

#include "hog.h"
#include "mathop.h"
#include <string.h>

Functions

VlHog * vl_hog_new (VlHogVariant variant, vl_size numOrientations, vl_bool transposed)
 Create a new HOG object. More...
 
void vl_hog_delete (VlHog *self)
 Delete a HOG object. More...
 
vl_size vl_hog_get_glyph_size (VlHog const *self)
 Get HOG glyph size. More...
 
vl_index const * vl_hog_get_permutation (VlHog const *self)
 Get HOG left-right flip permutation. More...
 
void vl_hog_set_use_bilinear_orientation_assignments (VlHog *self, vl_bool x)
 Turn bilinear interpolation of assignments on or off. More...
 
vl_bool vl_hog_get_use_bilinear_orientation_assignments (VlHog const *self)
 Tell whether assignments use bilinear interpolation or not. More...
 
void vl_hog_render (VlHog const *self, float *image, float const *descriptor, vl_size width, vl_size height)
 Render a HOG descriptor to a glyph image. More...
 
vl_size vl_hog_get_dimension (VlHog const *self)
 Get the dimension of the HOG features. More...
 
vl_size vl_hog_get_width (VlHog *self)
 Get the width of the HOG cell array. More...
 
vl_size vl_hog_get_height (VlHog *self)
 Get the height of the HOG cell array. More...
 
static void vl_hog_prepare_buffers (VlHog *self, vl_size width, vl_size height, vl_size cellSize)
 Prepare internal buffers. More...
 
void vl_hog_put_image (VlHog *self, float const *image, vl_size width, vl_size height, vl_size numChannels, vl_size cellSize)
 Process features starting from an image. More...
 
void vl_hog_put_polar_field (VlHog *self, float const *modulus, float const *angle, vl_bool directed, vl_size width, vl_size height, vl_size cellSize)
 Process features starting from a field in polar notation. More...
 
void vl_hog_extract (VlHog *self, float *features)
 Extract HOG features. More...
 

Detailed Description

Author
Andrea Vedaldi

Function Documentation

◆ vl_hog_delete()

void vl_hog_delete ( VlHog *  self)
Parameters
selfHOG object to delete.

◆ vl_hog_extract()

void vl_hog_extract ( VlHog *  self,
float *  features 
)
Parameters
selfHOG object.
featuresHOG features (output).

This method is called after vl_hog_put_image or vl_hog_put_polar_field in order to retrieve the computed HOG features. The buffer features must have the dimensions returned by vl_hog_get_width, vl_hog_get_height, and vl_hog_get_dimension.

◆ vl_hog_get_dimension()

vl_size vl_hog_get_dimension ( VlHog const *  self)
Parameters
selfHOG object.
Returns
imension of a HOG cell descriptors.

◆ vl_hog_get_glyph_size()

vl_size vl_hog_get_glyph_size ( VlHog const *  self)
Parameters
selfHOG object.
Returns
size (height and width) of a glyph.

◆ vl_hog_get_height()

vl_size vl_hog_get_height ( VlHog *  self)
Parameters
selfHOG object.
Returns
number of HOG cells in the vertical direction.

◆ vl_hog_get_permutation()

vl_index const* vl_hog_get_permutation ( VlHog const *  self)
Parameters
selfHOG object.
Returns
left-right permutation.

The function returns a pointer to an array permutation of vl_hog_get_dimension elements. Given a HOG descriptor (for a cell) hog, which is also a vector of vl_hog_get_dimension elements, the descriptor obtained for the same image flipped horizotnally is given by flippedHog[i] = hog[permutation[i]].

◆ vl_hog_get_use_bilinear_orientation_assignments()

vl_bool vl_hog_get_use_bilinear_orientation_assignments ( VlHog const *  self)
Parameters
selfHOG object.
Returns
true if orientations are be assigned with bilinear interpolation.

◆ vl_hog_get_width()

vl_size vl_hog_get_width ( VlHog *  self)
Parameters
selfHOG object.
Returns
number of HOG cells in the horizontal direction.

◆ vl_hog_new()

VlHog* vl_hog_new ( VlHogVariant  variant,
vl_size  numOrientations,
vl_bool  transposed 
)
Parameters
variantHOG descriptor variant.
numOrientationsnumber of distinguished orientations.
transposedwether images are transposed (column major).
Returns
the new HOG object.

The function creates a new HOG object to extract descriptors of the prescribed variant. The angular resolution is set by numOrientations, which specifies the number of undirected orientations. The object can work with column major images by setting transposed to true.

◆ vl_hog_prepare_buffers()

static void vl_hog_prepare_buffers ( VlHog *  self,
vl_size  width,
vl_size  height,
vl_size  cellSize 
)
static
Parameters
selfHOG object.
widthimage width.
heightimage height.
cellSizesize of a HOG cell.

◆ vl_hog_put_image()

void vl_hog_put_image ( VlHog *  self,
float const *  image,
vl_size  width,
vl_size  height,
vl_size  numChannels,
vl_size  cellSize 
)
Parameters
selfHOG object.
imageimage to process.
widthimage width.
heightimage height.
numChannelsnumber of image channles.
cellSizesize of a HOG cell.

The buffer hog must be a three-dimensional array. The first two dimensions are (width + cellSize/2)/cellSize and (height + cellSize/2)/cellSize, where divisions are integer. This is approximately width/cellSize and height/cellSize, adjusted so that the last cell is at least half contained in the image.

The image width and height must be not smaller than three pixels and not smaller than cellSize.

◆ vl_hog_put_polar_field()

void vl_hog_put_polar_field ( VlHog *  self,
float const *  modulus,
float const *  angle,
vl_bool  directed,
vl_size  width,
vl_size  height,
vl_size  cellSize 
)
Parameters
selfHOG object.
modulusimage gradient modulus.
angleimage gradient angle.
directedwrap the gradient angles at 2pi (directed) or pi (undirected).
widthimage width.
heightimage height.
cellSizesize of a HOG cell.

The function behaves like vl_hog_put_image, but foregoes the internal computation of the gradient field, allowing the user to specify their own. Angles are measure clockwise, the y axis pointing downwards, starting from the x axis (pointing to the right).

◆ vl_hog_render()

void vl_hog_render ( VlHog const *  self,
float *  image,
float const *  descriptor,
vl_size  width,
vl_size  height 
)
Parameters
selfHOG object.
imageglyph image (output).
descriptorHOG descriptor.
widthHOG descriptor width.
heightHOG descriptor height.

The function renders the HOG descriptor or filter descriptor as an image (for visualization) and stores the result in the buffer image. This buffer must be an array of dimensions width*glyphSize by height*glyphSize elements, where glyphSize is obtained from vl_hog_get_glyph_size and is the size in pixels of the image element used to represent the descriptor of one HOG cell.

◆ vl_hog_set_use_bilinear_orientation_assignments()

void vl_hog_set_use_bilinear_orientation_assignments ( VlHog *  self,
vl_bool  x 
)
Parameters
selfHOG object.
xtrue if orientations should be assigned with bilinear interpolation.