@eris/image
Advanced tools
Comparing version 0.2.1-alpha.13 to 0.2.1-alpha.14
@@ -15,3 +15,3 @@ "use strict"; | ||
const threshold = (options && options.threshold) || 20; | ||
let edges = []; | ||
let edgePixelIntensities = []; | ||
for (var y = 0; y < imageData.height; y++) { | ||
@@ -21,14 +21,15 @@ for (var x = 0; x < imageData.width; x++) { | ||
if (pixel > threshold) { | ||
edges.push(pixel); | ||
edgePixelIntensities.push(pixel); | ||
} | ||
} | ||
} | ||
edges = edges.sort((a, b) => a - b); | ||
const percentEdges = edges.length / imageData.data.length; | ||
const lowerQuartile = edges[Math.floor(edges.length / 4)]; | ||
const median = edges[Math.floor(edges.length / 2)]; | ||
const upperQuartile = edges[Math.floor((edges.length * 3) / 4)]; | ||
const lowerVentileAverage = computeAverage(edges, 0, Math.ceil(edges.length / 20)); | ||
const average = computeAverage(edges); | ||
const upperVentileAverage = computeAverage(edges, Math.floor((edges.length * 19) / 20)); | ||
edgePixelIntensities = edgePixelIntensities.sort((a, b) => a - b); | ||
const percentEdges = edgePixelIntensities.length / imageData.data.length; | ||
const lowerQuartile = edgePixelIntensities[Math.floor(edgePixelIntensities.length / 4)]; | ||
const median = edgePixelIntensities[Math.floor(edgePixelIntensities.length / 2)]; | ||
const upperQuartile = edgePixelIntensities[Math.floor((edgePixelIntensities.length * 3) / 4)]; | ||
const ventileBucketSize = Math.ceil(edgePixelIntensities.length / 20); | ||
const lowerVentileAverage = computeAverage(edgePixelIntensities, 0, ventileBucketSize); | ||
const average = computeAverage(edgePixelIntensities); | ||
const upperVentileAverage = computeAverage(edgePixelIntensities, edgePixelIntensities.length - ventileBucketSize); | ||
return { | ||
@@ -35,0 +36,0 @@ percentEdges, |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -9,2 +17,4 @@ const types = require("./types"); | ||
const sharpness_1 = require("./analyses/sharpness"); | ||
const histograms_1 = require("./analyses/histograms"); | ||
const composition_1 = require("./analyses/composition"); | ||
const exif_1 = require("@eris/exif"); | ||
@@ -113,10 +123,12 @@ const tone_1 = require("./transforms/tone"); | ||
toAnalysis() { | ||
if (!this._analyze) { | ||
return Promise.resolve({}); | ||
} | ||
const { hash, sharpness } = this._analyze; | ||
if (!hash && !sharpness) { | ||
return Promise.resolve({}); | ||
} | ||
return this.toImageData().then(imageData => { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this._analyze) { | ||
return Promise.resolve({}); | ||
} | ||
const { hash, sharpness, histograms, composition } = this._analyze; | ||
if (Object.keys(this._analyze).length === 0) { | ||
return Promise.resolve({}); | ||
} | ||
const imageData = yield this.toImageData(); | ||
const edges = sharpness || composition ? sobel_1.sobel(imageData, sharpness) : null; | ||
const analysis = {}; | ||
@@ -131,5 +143,10 @@ if (hash) { | ||
if (sharpness) { | ||
const edges = sobel_1.sobel(imageData, sharpness); | ||
analysis.sharpness = sharpness_1.sharpness(edges, sharpness); | ||
} | ||
if (histograms) { | ||
analysis.histograms = histograms_1.histograms(imageData, histograms); | ||
} | ||
if (composition) { | ||
analysis.composition = composition_1.composition(edges, composition); | ||
} | ||
return analysis; | ||
@@ -136,0 +153,0 @@ }); |
@@ -78,2 +78,4 @@ /// <reference types="node" /> | ||
sharpness?: ISharpnessOptions; | ||
histograms?: IHistogramOptions; | ||
composition?: ICompositionOptions; | ||
} | ||
@@ -104,2 +106,10 @@ export interface ISobelOptions { | ||
} | ||
export interface IHistogramOptions { | ||
buckets?: number; | ||
} | ||
export interface ICompositionOptions { | ||
ruleOfThirdsEdgeThreshold?: number; | ||
ruleOfThirdsFalloffPoint?: number; | ||
sharpnessAnalysis?: ISharpness; | ||
} | ||
export interface IMetadata { | ||
@@ -120,5 +130,15 @@ width: number; | ||
} | ||
export interface IHistogramsAnalysis { | ||
hue: number[]; | ||
saturation: number[]; | ||
lightness: number[]; | ||
} | ||
export interface ICompositionAnalysis { | ||
ruleOfThirds: number; | ||
} | ||
export interface IAnalysis { | ||
hash?: string; | ||
sharpness?: ISharpness; | ||
histograms?: IHistogramsAnalysis; | ||
composition?: ICompositionAnalysis; | ||
} | ||
@@ -125,0 +145,0 @@ export interface ISubselectOptions { |
@@ -21,3 +21,3 @@ /* tslint:disable */ | ||
let edges: number[] = [] | ||
let edgePixelIntensities: number[] = [] | ||
for (var y = 0; y < imageData.height; y++) { | ||
@@ -27,3 +27,3 @@ for (var x = 0; x < imageData.width; x++) { | ||
if (pixel > threshold) { | ||
edges.push(pixel) | ||
edgePixelIntensities.push(pixel) | ||
} | ||
@@ -33,12 +33,16 @@ } | ||
edges = edges.sort((a, b) => a - b) | ||
edgePixelIntensities = edgePixelIntensities.sort((a, b) => a - b) | ||
const percentEdges = edges.length / imageData.data.length | ||
const lowerQuartile = edges[Math.floor(edges.length / 4)] | ||
const median = edges[Math.floor(edges.length / 2)] | ||
const upperQuartile = edges[Math.floor((edges.length * 3) / 4)] | ||
const percentEdges = edgePixelIntensities.length / imageData.data.length | ||
const lowerQuartile = edgePixelIntensities[Math.floor(edgePixelIntensities.length / 4)] | ||
const median = edgePixelIntensities[Math.floor(edgePixelIntensities.length / 2)] | ||
const upperQuartile = edgePixelIntensities[Math.floor((edgePixelIntensities.length * 3) / 4)] | ||
const lowerVentileAverage = computeAverage(edges, 0, Math.ceil(edges.length / 20)) | ||
const average = computeAverage(edges) | ||
const upperVentileAverage = computeAverage(edges, Math.floor((edges.length * 19) / 20)) | ||
const ventileBucketSize = Math.ceil(edgePixelIntensities.length / 20) | ||
const lowerVentileAverage = computeAverage(edgePixelIntensities, 0, ventileBucketSize) | ||
const average = computeAverage(edgePixelIntensities) | ||
const upperVentileAverage = computeAverage( | ||
edgePixelIntensities, | ||
edgePixelIntensities.length - ventileBucketSize, | ||
) | ||
@@ -45,0 +49,0 @@ return { |
@@ -7,2 +7,4 @@ import * as types from './types' | ||
import {sharpness as computeSharpness} from './analyses/sharpness' | ||
import {histograms as computeHistograms} from './analyses/histograms' | ||
import {composition as computeComposition} from './analyses/composition' | ||
import {parse as parseEXIF, TIFFDecoder, INormalizedMetadata} from '@eris/exif' | ||
@@ -131,3 +133,3 @@ import {tone} from './transforms/tone' | ||
public toAnalysis(): Promise<types.IAnalysis> { | ||
public async toAnalysis(): Promise<types.IAnalysis> { | ||
if (!this._analyze) { | ||
@@ -137,24 +139,33 @@ return Promise.resolve({}) | ||
const {hash, sharpness} = this._analyze | ||
if (!hash && !sharpness) { | ||
const {hash, sharpness, histograms, composition} = this._analyze | ||
if (Object.keys(this._analyze).length === 0) { | ||
return Promise.resolve({}) | ||
} | ||
return this.toImageData().then(imageData => { | ||
const analysis: types.IAnalysis = {} | ||
if (hash) { | ||
switch (hash.method) { | ||
case types.HashMethod.PHash: | ||
default: | ||
analysis.hash = phash(imageData, hash.hashSize) | ||
} | ||
} | ||
const imageData = await this.toImageData() | ||
const edges = sharpness || composition ? sobel(imageData, sharpness) : null | ||
if (sharpness) { | ||
const edges = sobel(imageData, sharpness) | ||
analysis.sharpness = computeSharpness(edges, sharpness) | ||
const analysis: types.IAnalysis = {} | ||
if (hash) { | ||
switch (hash.method) { | ||
case types.HashMethod.PHash: | ||
default: | ||
analysis.hash = phash(imageData, hash.hashSize) | ||
} | ||
} | ||
return analysis | ||
}) | ||
if (sharpness) { | ||
analysis.sharpness = computeSharpness(edges!, sharpness) | ||
} | ||
if (histograms) { | ||
analysis.histograms = computeHistograms(imageData, histograms) | ||
} | ||
if (composition) { | ||
analysis.composition = computeComposition(edges!, composition) | ||
} | ||
return analysis | ||
} | ||
@@ -161,0 +172,0 @@ |
@@ -87,2 +87,4 @@ import {INormalizedMetadata} from '@eris/exif' | ||
sharpness?: ISharpnessOptions | ||
histograms?: IHistogramOptions | ||
composition?: ICompositionOptions | ||
} | ||
@@ -120,2 +122,12 @@ | ||
export interface IHistogramOptions { | ||
buckets?: number | ||
} | ||
export interface ICompositionOptions { | ||
ruleOfThirdsEdgeThreshold?: number | ||
ruleOfThirdsFalloffPoint?: number | ||
sharpnessAnalysis?: ISharpness | ||
} | ||
export interface IMetadata { | ||
@@ -138,5 +150,17 @@ width: number | ||
export interface IHistogramsAnalysis { | ||
hue: number[] | ||
saturation: number[] | ||
lightness: number[] | ||
} | ||
export interface ICompositionAnalysis { | ||
ruleOfThirds: number | ||
} | ||
export interface IAnalysis { | ||
hash?: string | ||
sharpness?: ISharpness | ||
histograms?: IHistogramsAnalysis | ||
composition?: ICompositionAnalysis | ||
} | ||
@@ -143,0 +167,0 @@ |
{ | ||
"name": "@eris/image", | ||
"version": "0.2.1-alpha.13", | ||
"version": "0.2.1-alpha.14", | ||
"description": "Collection of image manipulation libraries for node and the browser.", | ||
@@ -38,3 +38,3 @@ "main": "./dist/node-index.js", | ||
"dependencies": { | ||
"@eris/exif": "0.2.1-alpha.13", | ||
"@eris/exif": "0.2.1-alpha.14", | ||
"buffer": "^5.2.0", | ||
@@ -71,3 +71,3 @@ "file-type": "^7.0.1", | ||
}, | ||
"gitHead": "cb13624b9b3f57153cf5de8b7db1b5ad47068b19" | ||
"gitHead": "3c76ac43106c27d7966977be94dc97c635f04a8f" | ||
} |
@@ -22,1 +22,13 @@ # image | ||
``` | ||
## TODO Analysis Signals | ||
- parallelism | ||
- symmetry | ||
- sharpest edge window | ||
- center weigted edges | ||
- find faces | ||
- find eyes | ||
- find entity tags | ||
- shadow clipping | ||
- highlight clipping |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1735892
155
14928
34
+ Added@eris/exif@0.2.1-alpha.14(transitive)
- Removed@eris/exif@0.2.1-alpha.13(transitive)
Updated@eris/exif@0.2.1-alpha.14