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IAAM,CAEjB,CACF","file":"/npm/hog-features@1.0.0/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/hog-features@1.0.0/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nconst processing = require('./processingHog');\n\nconst PI_RAD = 180 / Math.PI;\n\nmodule.exports = {\n  extractHOG: extractHOG,\n  extractHistograms: extractHistograms\n};\n\n// also export all the functions from processing.js\nfor (var func in processing) {\n  module.exports[func] = processing[func];\n}\n\n/**\n * Extract the HOG of an image\n * @param {image} image - image to transform into a HOG descriptor\n * @param {object} options\n * @return {Array} Array with the value of the HOG descriptor\n */\n\nfunction extractHOG(image, options = {}) {\n  const {\n    blockSize = 2,\n    blockStride = blockSize / 2,\n    norm = 'L2'\n  } = options;\n\n  var histograms = extractHistograms(image, options);\n\n  var blocks = [];\n  var blocksHigh = histograms.length - blockSize + 1;\n  var blocksWide = histograms[0].length - blockSize + 1;\n\n  for (var y = 0; y < blocksHigh; y += blockStride) {\n    for (var x = 0; x < blocksWide; x += blockStride) {\n      var block = getBlock(histograms, x, y, blockSize);\n      normalize(block, norm);\n      blocks.push(block);\n    }\n  }\n  return Array.prototype.concat.apply([], blocks);\n}\n\n/**\n * Extract the histogram from an image\n * @param {image} image - image to transform into a HOG descriptor\n * @param {object} options\n * @return {Array<Array<number>>} Array 2D with the histogram, based on the gradient vectors\n */\n\nfunction extractHistograms(image, options = {}) {\n  var vectors = processing.gradientVectors(image);\n\n  var cellSize = options.cellSize || 4;\n  var bins = options.bins || 6;\n\n  var cellsWide = Math.floor(vectors[0].length / cellSize);\n  var cellsHigh = Math.floor(vectors.length / cellSize);\n\n  var histograms = new Array(cellsHigh);\n\n  for (var i = 0; i < cellsHigh; i++) {\n    histograms[i] = new Array(cellsWide);\n\n    for (var j = 0; j < cellsWide; j++) {\n      histograms[i][j] = getHistogram(vectors, j * cellSize, i * cellSize,\n        cellSize, bins);\n    }\n  }\n  return histograms;\n}\n\n/**\n * Extract a sqare block from a matrix\n * @param {Array<Array<number>>} matrix\n * @param {number} x\n * @param {number} y\n * @param {number} length\n * @return {Array<Array<number>>} square block extracted from the matrix\n */\n\nfunction getBlock(matrix, x, y, length) {\n  var square = [];\n  for (var i = y; i < y + length; i++) {\n    for (var j = x; j < x + length; j++) {\n      square.push(matrix[i][j]);\n    }\n  }\n  return Array.prototype.concat.apply([], square);\n}\n\n/**\n * Extract the histogram of a part of the image (a cell with coordinate x and y)\n * @param {Array<Array<number>>} elements - gradient vectors of the image\n * @param {number} x\n * @param {number} y\n * @param {number} size - cellSize\n * @param {number} bins - number of bins per histogram\n * @return {Array<number>} Array 1D with the histogram of the cell, based on the gradient vectors\n */\n\nfunction getHistogram(elements, x, y, size, bins) {\n  var histogram = new Array(bins).fill(0);\n\n  for (var i = 0; i < size; i++) {\n    for (var j = 0; j < size; j++) {\n      var vector = elements[y + i][x + j];\n      var bin = binFor(vector.orient, bins);\n      histogram[bin] += vector.mag;\n    }\n  }\n  return histogram;\n}\n\nfunction binFor(radians, bins) {\n  var angle = radians * (PI_RAD);\n  if (angle < 0) {\n    angle += 180;\n  }\n\n  // center the first bin around 0\n  angle += 90 / bins;\n  angle %= 180;\n\n  return Math.floor(angle / 180 * bins);\n}\n\n/**\n * Normalize a vector given with one of these norms : L1, L1-sqrt or L2 (norm by default). No return value, the input vector is modified.\n * @param {Array<number>} vector\n * @param {string} norm - should be \"L1\", \"L1-sqrt\" or \"L2\". Else, the norm will be the norm L2.\n */\n\nfunction normalize(vector, norm) {\n  var epsilon = 0.00001;\n  var sum, denom, i;\n  if (norm === 'L1') {\n    sum = 0;\n    for (i = 0; i < vector.length; i++) {\n      sum += Math.abs(vector[i]);\n    }\n    denom = sum + epsilon;\n\n    for (i = 0; i < vector.length; i++) {\n      vector[i] /= denom;\n    }\n  } else if (norm === 'L1-sqrt') {\n    sum = 0;\n    for (i = 0; i < vector.length; i++) {\n      sum += Math.abs(vector[i]);\n    }\n    denom = sum + epsilon;\n\n    for (i = 0; i < vector.length; i++) {\n      vector[i] = Math.sqrt(vector[i] / denom);\n    }\n  } else { // i.e norm === \"L2\"\n    sum = 0;\n    for (i = 0; i < vector.length; i++) {\n      sum += vector[i] * vector[i];\n    }\n    denom = Math.sqrt(sum + epsilon);\n    for (i = 0; i < vector.length; i++) {\n      vector[i] /= denom;\n    }\n  }\n}\n"]}