Initial commit

This commit is contained in:
robert committed 2025-05-30 18:13:30 +08:00
commit e49726988c
5445 files changed
+1089914

No files matched your search

+77
View File
@@ -0,0 +1,77 @@
import { JimpClass } from "@jimp/types";
export declare const methods: {
/**
* Calculates the perceptual hash
* @returns the perceptual hash
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.hash();
* ```
*/
pHash<I extends JimpClass>(image: I): string;
/**
* Generates a perceptual hash of the image <https://en.wikipedia.org/wiki/Perceptual_hashing>. And pads the string. Can configure base.
* @param base A number between 2 and 64 representing the base for the hash (e.g. 2 is binary, 10 is decimal, 16 is hex, 64 is base 64). Defaults to 64.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.hash(2); // binary
* image.hash(64); // base 64
* ```
*/
hash<I extends JimpClass>(image: I, base?: number): string;
/**
* Calculates the hamming distance of the current image and a hash based on their perceptual hash
* @param compareHash hash to compare to
* @returns a number ranging from 0 to 1, 0 means they are believed to be identical
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.distanceFromHash(image.pHash());
* ```
*/
distanceFromHash<I extends JimpClass>(image: I, compareHash: string): number;
};
/**
* Calculates the hamming distance of two images based on their perceptual hash
* @param img1 A Jimp image to compare
* @param img2 A Jimp image to compare
* @returns A number ranging from 0 to 1, 0 means they are believed to be identical
* @example
* ```ts
* import { Jimp, distance } from "jimp";
*
* const image1 = await Jimp.read("test/image.png");
* const image2 = await Jimp.read("test/image.png");
*
* distance(image1, image2); // 0.5
* ```
*/
export declare function distance<I extends JimpClass>(img1: I, img2: I): number;
/**
* Calculates the hamming distance of two images based on their perceptual hash
* @param hash1 A pHash
* @param hash2 A pHash
* @returns A number ranging from 0 to 1, 0 means they are believed to be identical
* @example
* ```ts
* import { Jimp, compareHashes } from "jimp";
*
* const image1 = await Jimp.read("test/image.png");
* const image2 = await Jimp.read("test/image.png");
*
* compareHashes(image1.pHash(), image2.pHash()); // 0.5
* ```
*/
export declare function compareHashes(hash1: string, hash2: string): number;
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAuBxC,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;OAWG;UACG,CAAC,SAAS,SAAS,SAAS,CAAC;IAKnC;;;;;;;;;;;;OAYG;SACE,CAAC,SAAS,SAAS,SAAS,CAAC;IAYlC;;;;;;;;;;;;OAYG;qBACc,CAAC,SAAS,SAAS,SAAS,CAAC,eAAe,MAAM;CAMpE,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,UAM7D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAGzD"}
+120
View File
@@ -0,0 +1,120 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.methods = void 0;
exports.distance = distance;
exports.compareHashes = compareHashes;
const any_base_1 = __importDefault(require("any-base"));
const phash_js_1 = __importDefault(require("./phash.js"));
// an array storing the maximum string length of hashes at various bases
// 0 and 1 do not exist as possible hash lengths
// prettier-ignore
const alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_";
// an array storing the maximum string length of hashes at various bases
// 0 and 1 do not exist as possible hash lengths
const maxHashLength = [NaN, NaN];
for (let i = 2; i < 65; i++) {
const maxHash = (0, any_base_1.default)(any_base_1.default.BIN, alphabet.slice(0, i))(new Array(64 + 1).join("1"));
maxHashLength.push(maxHash.length);
}
exports.methods = {
/**
* Calculates the perceptual hash
* @returns the perceptual hash
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.hash();
* ```
*/
pHash(image) {
const pHash = new phash_js_1.default();
return pHash.getHash(image);
},
/**
* Generates a perceptual hash of the image <https://en.wikipedia.org/wiki/Perceptual_hashing>. And pads the string. Can configure base.
* @param base A number between 2 and 64 representing the base for the hash (e.g. 2 is binary, 10 is decimal, 16 is hex, 64 is base 64). Defaults to 64.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.hash(2); // binary
* image.hash(64); // base 64
* ```
*/
hash(image, base = 64) {
if (base < 2 || base > 64) {
throw new Error("base must be a number between 2 and 64");
}
const subAlphabet = alphabet.slice(0, base);
const pHash = this.pHash(image);
const maxLength = maxHashLength[base];
return (0, any_base_1.default)(any_base_1.default.BIN, subAlphabet)(pHash).padStart(maxLength, "0");
},
/**
* Calculates the hamming distance of the current image and a hash based on their perceptual hash
* @param compareHash hash to compare to
* @returns a number ranging from 0 to 1, 0 means they are believed to be identical
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.distanceFromHash(image.pHash());
* ```
*/
distanceFromHash(image, compareHash) {
const pHash = new phash_js_1.default();
const currentHash = pHash.getHash(image);
return pHash.distance(currentHash, compareHash);
},
};
/**
* Calculates the hamming distance of two images based on their perceptual hash
* @param img1 A Jimp image to compare
* @param img2 A Jimp image to compare
* @returns A number ranging from 0 to 1, 0 means they are believed to be identical
* @example
* ```ts
* import { Jimp, distance } from "jimp";
*
* const image1 = await Jimp.read("test/image.png");
* const image2 = await Jimp.read("test/image.png");
*
* distance(image1, image2); // 0.5
* ```
*/
function distance(img1, img2) {
const phash = new phash_js_1.default();
const hash1 = phash.getHash(img1);
const hash2 = phash.getHash(img2);
return phash.distance(hash1, hash2);
}
/**
* Calculates the hamming distance of two images based on their perceptual hash
* @param hash1 A pHash
* @param hash2 A pHash
* @returns A number ranging from 0 to 1, 0 means they are believed to be identical
* @example
* ```ts
* import { Jimp, compareHashes } from "jimp";
*
* const image1 = await Jimp.read("test/image.png");
* const image2 = await Jimp.read("test/image.png");
*
* compareHashes(image1.pHash(), image2.pHash()); // 0.5
* ```
*/
function compareHashes(hash1, hash2) {
const phash = new phash_js_1.default();
return phash.distance(hash1, hash2);
}
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAsGA,4BAMC;AAiBD,sCAGC;AA/HD,wDAA+B;AAE/B,0DAAoC;AAEpC,wEAAwE;AACxE,gDAAgD;AAChD,kBAAkB;AAClB,MAAM,QAAQ,GACZ,kEAAkE,CAAC;AAErE,wEAAwE;AACxE,gDAAgD;AAChD,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAEjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;IAC5B,MAAM,OAAO,GAAG,IAAA,kBAAO,EACrB,kBAAO,CAAC,GAAG,EACX,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CACrB,CAAC,IAAI,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AAEY,QAAA,OAAO,GAAG;IACrB;;;;;;;;;;;OAWG;IACH,KAAK,CAAsB,KAAQ;QACjC,MAAM,KAAK,GAAG,IAAI,kBAAU,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,IAAI,CAAsB,KAAQ,EAAE,IAAI,GAAG,EAAE;QAC3C,IAA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AAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
+13
View File
@@ -0,0 +1,13 @@
import { JimpClass } from "@jimp/types";
declare class ImagePHash {
size: number;
smallerSize: number;
constructor(size?: number, smallerSize?: number);
distance(s1: string, s2: string): number;
/**
* Returns a 'binary string' (like. 001010111011100010) which is easy to do a hamming distance on.
*/
getHash(img: JimpClass): string;
}
export default ImagePHash;
//# sourceMappingURL=phash.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"phash.d.ts","sourceRoot":"","sources":["../../src/phash.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAWxC,cAAM,UAAU;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;gBAER,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;IAM/C,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAY/B;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,SAAS;CAyEvB;AAuDD,eAAe,UAAU,CAAC"}
+161
View File
@@ -0,0 +1,161 @@
"use strict";
/*
Copyright (c) 2011 Elliot Shepherd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const plugin_color_1 = require("@jimp/plugin-color");
const plugin_resize_1 = require("@jimp/plugin-resize");
const utils_1 = require("@jimp/utils");
// https://code.google.com/p/ironchef-team21/source/browse/ironchef_team21/src/ImagePHash.java
/*
* pHash-like image hash.
* Author: Elliot Shepherd (elliot@jarofworms.com
* Based On: http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
*/
class ImagePHash {
size;
smallerSize;
constructor(size, smallerSize) {
this.size = size || 32;
this.smallerSize = smallerSize || 8;
initCoefficients(this.size);
}
distance(s1, s2) {
let counter = 0;
for (let k = 0; k < s1.length; k++) {
if (s1[k] !== s2[k]) {
counter++;
}
}
return counter / s1.length;
}
/**
* Returns a 'binary string' (like. 001010111011100010) which is easy to do a hamming distance on.
*/
getHash(img) {
/* 1. Reduce size.
* Like Average Hash, pHash starts with a small image.
* However, the image is larger than 8x8; 32x32 is a good size.
* This is really done to simplify the DCT computation and not
* because it is needed to reduce the high frequencies.
*/
img = plugin_resize_1.methods.resize((0, utils_1.clone)(img), { w: this.size, h: this.size });
/* 2. Reduce color.
* The image is reduced to a grayscale just to further simplify
* the number of computations.
*/
img = plugin_color_1.methods.greyscale(img);
const vals = [];
for (let x = 0; x < img.bitmap.width; x++) {
const row = [];
for (let y = 0; y < img.bitmap.height; y++) {
row[y] = intToRGBA(img.getPixelColor(x, y)).b;
}
vals[x] = row;
}
/* 3. Compute the DCT.
* The DCT separates the image into a collection of frequencies
* and scalars. While JPEG uses an 8x8 DCT, this algorithm uses
* a 32x32 DCT.
*/
const dctVals = applyDCT(vals, this.size);
/* 4. Reduce the DCT.
* This is the magic step. While the DCT is 32x32, just keep the
* top-left 8x8. Those represent the lowest frequencies in the
* picture.
*/
/* 5. Compute the average value.
* Like the Average Hash, compute the mean DCT value (using only
* the 8x8 DCT low-frequency values and excluding the first term
* since the DC coefficient can be significantly different from
* the other values and will throw off the average).
*/
let total = 0;
for (let x = 0; x < this.smallerSize; x++) {
for (let y = 0; y < this.smallerSize; y++) {
total += dctVals[x][y];
}
}
const avg = total / (this.smallerSize * this.smallerSize);
/* 6. Further reduce the DCT.
* This is the magic step. Set the 64 hash bits to 0 or 1
* depending on whether each of the 64 DCT values is above or
* below the average value. The result doesn't tell us the
* actual low frequencies; it just tells us the very-rough
* relative scale of the frequencies to the mean. The result
* will not vary as long as the overall structure of the image
* remains the same; this can survive gamma and color histogram
* adjustments without a problem.
*/
let hash = "";
for (let x = 0; x < this.smallerSize; x++) {
for (let y = 0; y < this.smallerSize; y++) {
hash += dctVals[x][y] > avg ? "1" : "0";
}
}
return hash;
}
}
// DCT function stolen from http://stackoverflow.com/questions/4240490/problems-with-dct-and-idct-algorithm-in-java
/**
Convert a 32-bit integer color value to an RGBA object.
*/
function intToRGBA(i) {
const a = i & 0xff;
i >>>= 8;
const b = i & 0xff;
i >>>= 8;
const g = i & 0xff;
i >>>= 8;
const r = i & 0xff;
return { r, g, b, a };
}
const c = [];
function initCoefficients(size) {
for (let i = 1; i < size; i++) {
c[i] = 1;
}
c[0] = 1 / Math.sqrt(2.0);
}
function applyDCT(f, size) {
const N = size;
const F = [];
for (let u = 0; u < N; u++) {
const row = [];
for (let v = 0; v < N; v++) {
let sum = 0;
for (let i = 0; i < N; i++) {
for (let j = 0; j < N; j++) {
sum +=
Math.cos(((2 * i + 1) / (2.0 * N)) * u * Math.PI) *
Math.cos(((2 * j + 1) / (2.0 * N)) * v * Math.PI) *
f[i][j];
}
}
sum *= (c[u] * c[v]) / 4;
row[v] = sum;
F[u] = row;
}
}
return F;
}
exports.default = ImagePHash;
//# sourceMappingURL=phash.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"phash.js","sourceRoot":"","sources":["../../src/ph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G,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC3B,GAAG;wBACD,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;4BACjD,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;4BACjD,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAC;gBACd,CAAC;YACH,CAAC;YAED,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC,GAAG,CAAC,CAAC;YAC3B,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;YACb,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACb,CAAC;IACH,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC;AAED,kBAAe,UAAU,CAAC"}
+77
View File
@@ -0,0 +1,77 @@
import { JimpClass } from "@jimp/types";
export declare const methods: {
/**
* Calculates the perceptual hash
* @returns the perceptual hash
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.hash();
* ```
*/
pHash<I extends JimpClass>(image: I): string;
/**
* Generates a perceptual hash of the image <https://en.wikipedia.org/wiki/Perceptual_hashing>. And pads the string. Can configure base.
* @param base A number between 2 and 64 representing the base for the hash (e.g. 2 is binary, 10 is decimal, 16 is hex, 64 is base 64). Defaults to 64.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.hash(2); // binary
* image.hash(64); // base 64
* ```
*/
hash<I extends JimpClass>(image: I, base?: number): string;
/**
* Calculates the hamming distance of the current image and a hash based on their perceptual hash
* @param compareHash hash to compare to
* @returns a number ranging from 0 to 1, 0 means they are believed to be identical
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.distanceFromHash(image.pHash());
* ```
*/
distanceFromHash<I extends JimpClass>(image: I, compareHash: string): number;
};
/**
* Calculates the hamming distance of two images based on their perceptual hash
* @param img1 A Jimp image to compare
* @param img2 A Jimp image to compare
* @returns A number ranging from 0 to 1, 0 means they are believed to be identical
* @example
* ```ts
* import { Jimp, distance } from "jimp";
*
* const image1 = await Jimp.read("test/image.png");
* const image2 = await Jimp.read("test/image.png");
*
* distance(image1, image2); // 0.5
* ```
*/
export declare function distance<I extends JimpClass>(img1: I, img2: I): number;
/**
* Calculates the hamming distance of two images based on their perceptual hash
* @param hash1 A pHash
* @param hash2 A pHash
* @returns A number ranging from 0 to 1, 0 means they are believed to be identical
* @example
* ```ts
* import { Jimp, compareHashes } from "jimp";
*
* const image1 = await Jimp.read("test/image.png");
* const image2 = await Jimp.read("test/image.png");
*
* compareHashes(image1.pHash(), image2.pHash()); // 0.5
* ```
*/
export declare function compareHashes(hash1: string, hash2: string): number;
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAuBxC,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;OAWG;UACG,CAAC,SAAS,SAAS,SAAS,CAAC;IAKnC;;;;;;;;;;;;OAYG;SACE,CAAC,SAAS,SAAS,SAAS,CAAC;IAYlC;;;;;;;;;;;;OAYG;qBACc,CAAC,SAAS,SAAS,SAAS,CAAC,eAAe,MAAM;CAMpE,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,UAM7D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAGzD"}
+112
View File
@@ -0,0 +1,112 @@
import anyBase from "any-base";
import ImagePHash from "./phash.js";
// an array storing the maximum string length of hashes at various bases
// 0 and 1 do not exist as possible hash lengths
// prettier-ignore
const alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_";
// an array storing the maximum string length of hashes at various bases
// 0 and 1 do not exist as possible hash lengths
const maxHashLength = [NaN, NaN];
for (let i = 2; i < 65; i++) {
const maxHash = anyBase(anyBase.BIN, alphabet.slice(0, i))(new Array(64 + 1).join("1"));
maxHashLength.push(maxHash.length);
}
export const methods = {
/**
* Calculates the perceptual hash
* @returns the perceptual hash
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.hash();
* ```
*/
pHash(image) {
const pHash = new ImagePHash();
return pHash.getHash(image);
},
/**
* Generates a perceptual hash of the image <https://en.wikipedia.org/wiki/Perceptual_hashing>. And pads the string. Can configure base.
* @param base A number between 2 and 64 representing the base for the hash (e.g. 2 is binary, 10 is decimal, 16 is hex, 64 is base 64). Defaults to 64.
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.hash(2); // binary
* image.hash(64); // base 64
* ```
*/
hash(image, base = 64) {
if (base < 2 || base > 64) {
throw new Error("base must be a number between 2 and 64");
}
const subAlphabet = alphabet.slice(0, base);
const pHash = this.pHash(image);
const maxLength = maxHashLength[base];
return anyBase(anyBase.BIN, subAlphabet)(pHash).padStart(maxLength, "0");
},
/**
* Calculates the hamming distance of the current image and a hash based on their perceptual hash
* @param compareHash hash to compare to
* @returns a number ranging from 0 to 1, 0 means they are believed to be identical
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* image.distanceFromHash(image.pHash());
* ```
*/
distanceFromHash(image, compareHash) {
const pHash = new ImagePHash();
const currentHash = pHash.getHash(image);
return pHash.distance(currentHash, compareHash);
},
};
/**
* Calculates the hamming distance of two images based on their perceptual hash
* @param img1 A Jimp image to compare
* @param img2 A Jimp image to compare
* @returns A number ranging from 0 to 1, 0 means they are believed to be identical
* @example
* ```ts
* import { Jimp, distance } from "jimp";
*
* const image1 = await Jimp.read("test/image.png");
* const image2 = await Jimp.read("test/image.png");
*
* distance(image1, image2); // 0.5
* ```
*/
export function distance(img1, img2) {
const phash = new ImagePHash();
const hash1 = phash.getHash(img1);
const hash2 = phash.getHash(img2);
return phash.distance(hash1, hash2);
}
/**
* Calculates the hamming distance of two images based on their perceptual hash
* @param hash1 A pHash
* @param hash2 A pHash
* @returns A number ranging from 0 to 1, 0 means they are believed to be identical
* @example
* ```ts
* import { Jimp, compareHashes } from "jimp";
*
* const image1 = await Jimp.read("test/image.png");
* const image2 = await Jimp.read("test/image.png");
*
* compareHashes(image1.pHash(), image2.pHash()); // 0.5
* ```
*/
export function compareHashes(hash1, hash2) {
const phash = new ImagePHash();
return phash.distance(hash1, hash2);
}
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,UAAU,CAAC;AAE/B,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,wEAAwE;AACxE,gDAAgD;AAChD,kBAAkB;AAClB,MAAM,QAAQ,GACZ,kEAAkE,CAAC;AAErE,wEAAwE;AACxE,gDAAgD;AAChD,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAEjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,E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OAAO,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAClD,CAAC;CACF,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,QAAQ,CAAsB,IAAO,EAAE,IAAO;IAC5D,MAAM,KAAK,GAAG,IAAI,UAAU,EAAE,CAAC;IAC/B,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAElC,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,KAAa;IACxD,MAAM,KAAK,GAAG,IAAI,UAAU,EAAE,CAAC;IAC/B,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "module"
}
+13
View File
@@ -0,0 +1,13 @@
import { JimpClass } from "@jimp/types";
declare class ImagePHash {
size: number;
smallerSize: number;
constructor(size?: number, smallerSize?: number);
distance(s1: string, s2: string): number;
/**
* Returns a 'binary string' (like. 001010111011100010) which is easy to do a hamming distance on.
*/
getHash(img: JimpClass): string;
}
export default ImagePHash;
//# sourceMappingURL=phash.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"phash.d.ts","sourceRoot":"","sources":["../../src/phash.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAWxC,cAAM,UAAU;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;gBAER,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;IAM/C,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAY/B;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,SAAS;CAyEvB;AAuDD,eAAe,UAAU,CAAC"}
+159
View File
@@ -0,0 +1,159 @@
/*
Copyright (c) 2011 Elliot Shepherd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { methods as color } from "@jimp/plugin-color";
import { methods } from "@jimp/plugin-resize";
import { clone } from "@jimp/utils";
// https://code.google.com/p/ironchef-team21/source/browse/ironchef_team21/src/ImagePHash.java
/*
* pHash-like image hash.
* Author: Elliot Shepherd (elliot@jarofworms.com
* Based On: http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
*/
class ImagePHash {
size;
smallerSize;
constructor(size, smallerSize) {
this.size = size || 32;
this.smallerSize = smallerSize || 8;
initCoefficients(this.size);
}
distance(s1, s2) {
let counter = 0;
for (let k = 0; k < s1.length; k++) {
if (s1[k] !== s2[k]) {
counter++;
}
}
return counter / s1.length;
}
/**
* Returns a 'binary string' (like. 001010111011100010) which is easy to do a hamming distance on.
*/
getHash(img) {
/* 1. Reduce size.
* Like Average Hash, pHash starts with a small image.
* However, the image is larger than 8x8; 32x32 is a good size.
* This is really done to simplify the DCT computation and not
* because it is needed to reduce the high frequencies.
*/
img = methods.resize(clone(img), { w: this.size, h: this.size });
/* 2. Reduce color.
* The image is reduced to a grayscale just to further simplify
* the number of computations.
*/
img = color.greyscale(img);
const vals = [];
for (let x = 0; x < img.bitmap.width; x++) {
const row = [];
for (let y = 0; y < img.bitmap.height; y++) {
row[y] = intToRGBA(img.getPixelColor(x, y)).b;
}
vals[x] = row;
}
/* 3. Compute the DCT.
* The DCT separates the image into a collection of frequencies
* and scalars. While JPEG uses an 8x8 DCT, this algorithm uses
* a 32x32 DCT.
*/
const dctVals = applyDCT(vals, this.size);
/* 4. Reduce the DCT.
* This is the magic step. While the DCT is 32x32, just keep the
* top-left 8x8. Those represent the lowest frequencies in the
* picture.
*/
/* 5. Compute the average value.
* Like the Average Hash, compute the mean DCT value (using only
* the 8x8 DCT low-frequency values and excluding the first term
* since the DC coefficient can be significantly different from
* the other values and will throw off the average).
*/
let total = 0;
for (let x = 0; x < this.smallerSize; x++) {
for (let y = 0; y < this.smallerSize; y++) {
total += dctVals[x][y];
}
}
const avg = total / (this.smallerSize * this.smallerSize);
/* 6. Further reduce the DCT.
* This is the magic step. Set the 64 hash bits to 0 or 1
* depending on whether each of the 64 DCT values is above or
* below the average value. The result doesn't tell us the
* actual low frequencies; it just tells us the very-rough
* relative scale of the frequencies to the mean. The result
* will not vary as long as the overall structure of the image
* remains the same; this can survive gamma and color histogram
* adjustments without a problem.
*/
let hash = "";
for (let x = 0; x < this.smallerSize; x++) {
for (let y = 0; y < this.smallerSize; y++) {
hash += dctVals[x][y] > avg ? "1" : "0";
}
}
return hash;
}
}
// DCT function stolen from http://stackoverflow.com/questions/4240490/problems-with-dct-and-idct-algorithm-in-java
/**
Convert a 32-bit integer color value to an RGBA object.
*/
function intToRGBA(i) {
const a = i & 0xff;
i >>>= 8;
const b = i & 0xff;
i >>>= 8;
const g = i & 0xff;
i >>>= 8;
const r = i & 0xff;
return { r, g, b, a };
}
const c = [];
function initCoefficients(size) {
for (let i = 1; i < size; i++) {
c[i] = 1;
}
c[0] = 1 / Math.sqrt(2.0);
}
function applyDCT(f, size) {
const N = size;
const F = [];
for (let u = 0; u < N; u++) {
const row = [];
for (let v = 0; v < N; v++) {
let sum = 0;
for (let i = 0; i < N; i++) {
for (let j = 0; j < N; j++) {
sum +=
Math.cos(((2 * i + 1) / (2.0 * N)) * u * Math.PI) *
Math.cos(((2 * j + 1) / (2.0 * N)) * v * Math.PI) *
f[i][j];
}
}
sum *= (c[u] * c[v]) / 4;
row[v] = sum;
F[u] = row;
}
}
return F;
}
export default ImagePHash;
//# sourceMappingURL=phash.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"phash.js","sourceRoot":"","sources":["../../src/phash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;EAoBE;AAEF,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,8FAA8F;AAE9F;;;;GAIG;AAEH,MAAM,UAAU;IACd,IAAI,CAAS;IACb,WAAW,CAAS;IAEpB,YAAY,IAAa,EAAE,WAAoB;QAC7C,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,CAAC,CAAC;QACpC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,QAAQ,CAAC,EAAU,EAAE,EAAU;QAC7B,IAAI,OAAO,GAAG,CAAC,CAAC;QAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,C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