#phog-descriptor
phog-descriptor extracts a Pyramid Histogram of Oriented Gradients descriptor from an image (canvas):
var hog = require("hog-descriptor");
var descriptor = hog.extractPHOG(canvas);
console.log(descriptor);
Install
For node.js:
npm install hog-descriptor
API
extractHOG()
takes options for the cell size (default is 4
pixels), block size (default is 2
cells), block stride (default is blockSize / 2
), number of bins per orientation histogram (default is 6
), and block normalization method (one of "L1"
, "L1-sqrt"
, and default "L2"
):
extractPHOG()
takes options for number of levels(default is3
), other parameters are same as that of extractHOG()
var options = {
cellSize: 4,
blockSize: 2,
blockStride: 1,
bins: 6,
norm: 'L2'
}
var descriptor = hog.extractHOG(canvas, options);
Other Goodies
In the process of computing a HOG descriptor, a bunch of other intermediate things have to be computed, like the image gradient, so these steps are also provided as secret goodies on the library:
intensities
Get a 2d array of the pixel intensities (normalized to fall between 0
and 1
):
var intensities = hog.intensities(canvas);
The return array is indexed first by row (y direction) then by column (x direction).
gradients
Get a 2d array of the image gradient at each pixel of the canvas with respect to the vertical and horizontal directions using a [-1, 0, 1]
filter:
var gradients = hog.gradients(canvas);
Return looks like this:
{
x: [[0.0084, 0.354] ],
y: [[0.056, 0.7888] ]
}
gradientVectors
Get a 2d array of the gradient vectors at each pixel of the canvas:
var vectors = hog.gradientVectors(canvas);
Return value is the vector at each pixel with mag
and orient
for magnitude and orientation (in radians):
[[{ mag: 0.4, orient: -1.52} ]]
drawGreyscale
Greyscales a canvas:
hog.drawGreyscale(canvas)
drawGradient
Draws the gradient of the canvas with respect to 'x' or 'y' direction:
hog.drawGradient(canvas, 'x')
hog.drawGradient(canvas, 'y')
drawMagnitude
Draws the magnitude of the gradient vectors over the canvas:
hog.drawMagnitude(canvas)