npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

phog-descriptor

v0.5.0

Published

Pyramid Histogram of Oriented Gradients (HOG) descriptor extractor

Downloads

2

Readme

#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); // [0.455, 0.003, 0.987, ...]

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,    // length of cell in px
  blockSize: 2,   // length of block in number of cells
  blockStride: 1, // number of cells to slide block window by (block overlap)
  bins: 6,        // bins per histogram
  norm: 'L2'      // block normalization method
}

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)

x-gradient

drawGradient

Draws the gradient of the canvas with respect to 'x' or 'y' direction:

hog.drawGradient(canvas, 'x')

x-gradient

hog.drawGradient(canvas, 'y')

y-gradient

drawMagnitude

Draws the magnitude of the gradient vectors over the canvas:

hog.drawMagnitude(canvas)

magnitude