@thi.ng/pixel-analysis
Version:
Image color & feature analysis utilities
153 lines • 5.59 kB
TypeScript
import type { ReadonlyVec } from "@thi.ng/vectors";
import type { TemperatureResult } from "./api.js";
/**
* Iterator consuming HSV colors and only yielding those matching given hue
* range and minimum saturation (all normalized in [0,1] range).
*
* @remarks
* If given a pixel buffer as input, it MUST be in `FLOAT_HSVA` format.
*
* If `minHue` is greater than `maxHue`, the range will be interpreted to wrap
* around at 1. E.g. the range `[0.8, 0.2]` selects hues >= 0.8 and hues
* < 0.2.
*
* @param colors
* @param minHue
* @param maxHue
* @param minSat
*/
export declare function selectHueRange(colors: Iterable<ReadonlyVec>, minHue: number, maxHue: number, minSat: number): Generator<ReadonlyVec, void, unknown>;
/**
* Similar to {@link selectHueRange}, but only yields indices/IDs of matching
* colors.
*
* @remarks
* See {@link selectHueRange} for details about hue ranges.
*
* @param colors
* @param minHue
* @param maxHue
* @param minSat
*/
export declare function selectHueRangeIDs(colors: Iterable<ReadonlyVec>, minHue: number, maxHue: number, minSat: number): Generator<number, void, unknown>;
/**
* Similar to {@link selectHueRange}, but only returns a count of inputs
* matching given hue range and minimum saturation (all normalized in [0,1]
* range).
*
* @remarks
* See {@link selectHueRange} for details about hue ranges.
*
* @param colors
* @param minHue
* @param maxHue
* @param minSat
*/
export declare const countHueRange: (colors: Iterable<ReadonlyVec>, minHue: number, maxHue: number, minSat: number) => number;
/**
* Takes a list of HSV colors, a list of min/max hue ranges and a min saturation
* (all normalized in [0,1] range). Computes the normalized area of all matching
* colors.
*
* @remarks
* If given a pixel buffer as input, it MUST be in `FLOAT_HSVA` format. Also see
* {@link temperature}.
*
* See {@link selectHueRange} for details about hue ranges.
*
* @param colors
* @param hueRanges
* @param minSat
*/
export declare const hueRangeArea: (colors: Iterable<ReadonlyVec>, hueRanges: [number, number][], minSat?: number) => number;
/**
* Takes a list of hue ranges and computes the area-weighted mean intensity of
* matching pixels in the given image. Also see {@link temperatureIntensity}.
*
* @remarks
* If given a pixel buffer as input, it MUST be in `FLOAT_HSVA` format.
*
* Intensity here means the product of HSV `saturation * brightness`.
*
* See {@link selectHueRange} for details about hue ranges.
*
* @param colors
* @param hueRanges
* @param minSat
*/
export declare const hueRangeAreaIntensity: (colors: Iterable<ReadonlyVec>, hueRanges: [number, number][], minSat?: number) => number;
/**
* Computes the average intensity of given HSV colors. Intensity here means the
* product of `saturation * value` (ignoring hues).
*
* @remarks
* If given a pixel buffer as input, it MUST be in `FLOAT_HSVA` format.
*
* @param colors
*/
export declare const meanIntensity: (colors: Iterable<ReadonlyVec>) => number;
/**
* Constructs a min/max range of given normalized `hues` around given `mean` hue
* (also normalized), considering circular wrap-around. If `min > max` in the
* result `[min,max]`, then the hue range is crossing zero.
*
* @param hues
* @param mean
*/
export declare const hueRange: (values: import("@thi.ng/api").NumericArray, mean: number) => import("@thi.ng/metrics").Range;
/**
* Computes an abstract measure of a normalized "color temperature" of the given
* HSV `colors` (also normalized in [0,1] range). Results closer to 1.0 indicate
* a prevalence of warmer (red/orange) colors, results closer to -1.0 mean more
* colder/blue-ish colors present.
*
* @remarks
* Computation is as follows:
* - Discard colors with lower saturation than given `minSat`
* - Compute normalized area (percentage) of qualifying saturated colors
* - Compute the histogram for 12 evenly spread hues
* - Produce a weighted list of hue angles, based on histogram
* - Compute circular mean of hue angles
* - Use {@link hueTemperature} to compute normalized temperature in [-1,1] range
* - Scale temparature by normlized area
* - Return object of the various result metrics
*
* If given a pixel buffer as input, it MUST be in `FLOAT_HSVA` format.
*
* Also see {@link temperatureIntensity}.
*
* @param colors
* @param minSat
* @param coeffs
*/
export declare const temperature: (colors: Iterable<ReadonlyVec>, minSat?: number, coeffs?: typeof DEFAULT_TEMPERATURE_COEFFS) => TemperatureResult;
/**
* Default temperature curve hues/coefficients for {@link hueTemperature}.
*
* @remarks
* The four values (all in [0,1] range) are to be giving in this order:
*
* - A: start hue of warm falloff
* - B: end hue of warm falloff
* - C: start hue of warm rise
* - D: end hue of warm rise
*
* Note: The hot point is fixed at 0 (aka red) and the cold point is fixed at
* 2/3 (= 0.666... aka blue), meaning C & D MUST be greater.
*/
export declare const DEFAULT_TEMPERATURE_COEFFS: [number, number, number, number];
/**
* Computes an abstract measure of a normalized "color temperature" ([-1,1]
* range) for the given `hue` (in [0,1] range). Red/orange/yellow hues produce
* results close to 1.0, cyan/blue/purple-ish hues produce results closer to
* -1.0.
*
* @remarks
* Uses one of two smoothstep curves for non-linear interpolation, depending on
* input hue.
*
* @param hue
* @param coeffs
*/
export declare const hueTemperature: (hue: number, [a, b, c, d]?: [number, number, number, number]) => number;
//# sourceMappingURL=hues.d.ts.map