🔧 WIP first draft of rgb histogram using image-js

This commit is contained in:
2022-05-03 09:23:22 -07:00
parent c8d10a91c6
commit 2ceb8a7549
3 changed files with 932 additions and 1179 deletions

2073
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -51,8 +51,8 @@
"dotenv": "^10.0.0", "dotenv": "^10.0.0",
"filename-parser": "^1.0.4", "filename-parser": "^1.0.4",
"fs-extra": "^10.0.0", "fs-extra": "^10.0.0",
"image-js": "^0.34.0",
"imghash": "^0.0.9", "imghash": "^0.0.9",
"jimp": "^0.16.1",
"jsdom": "^15.2.1", "jsdom": "^15.2.1",
"klaw": "^4.0.1", "klaw": "^4.0.1",
"leven": "^3.1.0", "leven": "^3.1.0",

View File

@@ -4,6 +4,7 @@ const imghash = require("imghash");
const leven = require("leven"); const leven = require("leven");
import { isNull, reject } from "lodash"; import { isNull, reject } from "lodash";
import Jimp from "jimp"; import Jimp from "jimp";
const { Image } = require("image-js");
export const extractMetadataFromImage = async ( export const extractMetadataFromImage = async (
imageFilePath: string imageFilePath: string
@@ -54,32 +55,17 @@ export const getColorHistogramData = async (
isValueHistogram: Boolean isValueHistogram: Boolean
) => { ) => {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
sharp(inputFilePath) let image = await Image.load(inputFilePath);
.toBuffer() console.log(image.getHistograms());
.then((new_image) => { const histograms = image.getHistograms();
let index = 0; let rgb_values = {
let rgb_values = { r: [], g: [], b: [] }; r: histograms[0],
while (index < new_image.length) { g: histograms[1],
b: histograms[2],
let point = {
red: new_image[index] & 0xFF,
green: (new_image[index + 1] >> 8) & 0xFF,
blue: (new_image[index + 2] >> 16) & 0xFF,
}; };
rgb_values.r.push(point.red);
rgb_values.g.push(point.green);
rgb_values.b.push(point.blue);
index = index + 3;
}
console.log(rgb_values);
resolve(rgb_values); resolve(rgb_values);
}) }).catch((err) => reject(err));
.catch((e) => {
reject(e);
});
});
}; };
export const calculateLevenshteinDistance = async ( export const calculateLevenshteinDistance = async (