Permalink
Browse files

function to extract descriptor from intensity matrix

  • Loading branch information...
1 parent d1f5ba8 commit b48c13a19ce1662c0ab106e0739a6e6e60fed8f9 @harthur committed Jun 5, 2012
Showing with 35 additions and 18 deletions.
  1. +18 −5 hog.js
  2. +17 −13 processing.js
View
23 hog.js
@@ -1,23 +1,36 @@
var processing = require("./processing"),
norms = require("./norms");
+module.exports = {
+ extractHOG: extractHOG,
+ extractHOGFromIntensities: extractHOGFromIntensities
+}
+
// also export all the functions from processing.js
for (var func in processing) {
- exports[func] = processing[func];
+ module.exports[func] = processing[func];
}
-exports.extractHOG = function(canvas, options) {
+function extractHOG(canvas, options) {
+ var intensities = processing.intensities(canvas);
+ return extractHOGFromIntensities(intensities, options);
+}
+
+function extractHOGFromIntensities(intensities, options) {
options = options || {};
var cellSize = options.cellSize || 4;
var blockSize = options.blockSize || 2;
var bins = options.bins || 6;
var blockStride = options.blockStride || (blockSize / 2);
var normalize = norms[options.norm || "L2"];
- var vectors = processing.gradientVectors(canvas);
+ var vectors = processing._gradientVectors(intensities);
+
+ var height = vectors.length;
+ var width = vectors[0].length;
- var cellsWide = Math.floor(canvas.width / cellSize);
- var cellsHigh = Math.floor(canvas.height / cellSize);
+ var cellsWide = Math.floor(width / cellSize);
+ var cellsHigh = Math.floor(height / cellSize);
var histograms = new Array(cellsHigh);
for (var i = 0; i < cellsHigh; i++) {
View
@@ -1,18 +1,22 @@
var processing = {
- intensities: function(canvas) {
- var context = canvas.getContext("2d");
- var imageData = context.getImageData(0, 0, canvas.width, canvas.height);
+ intensities: function(imagedata) {
+ if (!imagedata.data) {
+ // it's a canvas, extract the imagedata
+ var canvas = imagedata;
+ var context = canvas.getContext("2d");
+ imagedata = context.getImageData(0, 0, canvas.width, canvas.height);
+ }
- var lumas = new Array(canvas.height);
- for (var y = 0; y < imageData.height; y++) {
- lumas[y] = new Array(canvas.width);
-
- for (var x = 0; x < imageData.height; x++) {
- var i = x * 4 + y * 4 * imageData.width;
- var r = imageData.data[i],
- g = imageData.data[i + 1],
- b = imageData.data[i + 2],
- a = imageData.data[i + 3];
+ var lumas = new Array(imagedata.height);
+ for (var y = 0; y < imagedata.height; y++) {
+ lumas[y] = new Array(imagedata.width);
+
+ for (var x = 0; x < imagedata.height; x++) {
+ var i = x * 4 + y * 4 * imagedata.width;
+ var r = imagedata.data[i],
+ g = imagedata.data[i + 1],
+ b = imagedata.data[i + 2],
+ a = imagedata.data[i + 3];
var luma = a == 0 ? 1 : (r * 299/1000 + g * 587/1000
+ b * 114/1000) / 255;

0 comments on commit b48c13a

Please sign in to comment.