hog

menpo.feature.hog(pixels, mode='dense', algorithm='dalaltriggs', num_bins=9, cell_size=8, block_size=2, signed_gradient=True, l2_norm_clip=0.2, window_height=1, window_width=1, window_unit='blocks', window_step_vertical=1, window_step_horizontal=1, window_step_unit='pixels', padding=True, verbose=False)[source]

Extracts Histograms of Oriented Gradients (HOG) features from the input image.

Parameters
  • pixels (Image or subclass or (C, X, Y, ..., Z) ndarray) – Either the image object itself or an array with the pixels. The first dimension is interpreted as channels. This means an N-dimensional image is represented by an N+1 dimensional array.

  • mode ({dense, sparse}, optional) –

    The sparse case refers to the traditional usage of HOGs, so predefined parameters values are used.

    The sparse case of dalaltriggs algorithm sets window_height = window_width = block_size and window_step_horizontal = window_step_vertical = cell_size.

    The sparse case of zhuramanan algorithm sets window_height = window_width = 3 * cell_size and window_step_horizontal = window_step_vertical = cell_size.

    In the dense case, the user can choose values for window_height, window_width, window_unit, window_step_vertical, window_step_horizontal, window_step_unit and padding to customize the HOG calculation.

  • window_height (float, optional) – Defines the height of the window. The metric unit is defined by window_unit.

  • window_width (float, optional) – Defines the width of the window. The metric unit is defined by window_unit.

  • window_unit ({blocks, pixels}, optional) – Defines the metric unit of the window_height and window_width parameters.

  • window_step_vertical (float, optional) – Defines the vertical step by which the window is moved, thus it controls the features’ density. The metric unit is defined by window_step_unit.

  • window_step_horizontal (float, optional) – Defines the horizontal step by which the window is moved, thus it controls the features’ density. The metric unit is defined by window_step_unit.

  • window_step_unit ({pixels, cells}, optional) – Defines the metric unit of the window_step_vertical and window_step_horizontal parameters.

  • padding (bool, optional) – If True, the output image is padded with zeros to match the input image’s size.

  • algorithm ({dalaltriggs, zhuramanan}, optional) – Specifies the algorithm used to compute HOGs. dalaltriggs is the implementation of [1] and zhuramanan is the implementation of [2].

  • cell_size (float, optional) – Defines the cell size in pixels. This value is set to both the width and height of the cell. This option is valid for both algorithms.

  • block_size (float, optional) – Defines the block size in cells. This value is set to both the width and height of the block. This option is valid only for the dalaltriggs algorithm.

  • num_bins (float, optional) – Defines the number of orientation histogram bins. This option is valid only for the dalaltriggs algorithm.

  • signed_gradient (bool, optional) – Flag that defines whether we use signed or unsigned gradient angles. This option is valid only for the dalaltriggs algorithm.

  • l2_norm_clip (float, optional) – Defines the clipping value of the gradients’ L2-norm. This option is valid only for the dalaltriggs algorithm.

  • verbose (bool, optional) – Flag to print HOG related information.

Returns

hog (Image or subclass or (X, Y, ..., Z, K) ndarray) – The HOG features image. It has the same type as the input pixels. The output number of channels in the case of dalaltriggs is K = num_bins * block_size *block_size and K = 31 in the case of zhuramanan.

Raises
  • ValueError – HOG features mode must be either dense or sparse

  • ValueError – Algorithm must be either dalaltriggs or zhuramanan

  • ValueError – Number of orientation bins must be > 0

  • ValueError – Cell size (in pixels) must be > 0

  • ValueError – Block size (in cells) must be > 0

  • ValueError – Value for L2-norm clipping must be > 0.0

  • ValueError – Window height must be >= block size and <= image height

  • ValueError – Window width must be >= block size and <= image width

  • ValueError – Window unit must be either pixels or blocks

  • ValueError – Horizontal window step must be > 0

  • ValueError – Vertical window step must be > 0

  • ValueError – Window step unit must be either pixels or cells

References

1

N. Dalal and B. Triggs, “Histograms of oriented gradients for human detection”, Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2005.

2

X. Zhu, D. Ramanan. “Face detection, pose estimation and landmark localization in the wild”, Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2012.