UNPKG

@thi.ng/pixel-dominant-colors

Version:

k-means based dominant color extraction from images/pixel buffers

53 lines 1.88 kB
import type { Fn2, NumericArray } from "@thi.ng/api"; import type { KMeansOpts } from "@thi.ng/k-means"; import type { FloatBuffer } from "@thi.ng/pixel/float"; /** * Options for {@link dominantColors}, an extension of * [KMeansOpts](https://docs.thi.ng/umbrella/k-means/interfaces/KMeansOpts.html). */ export interface DominantColorOpts extends KMeansOpts { /** * Predicate used to only include pixels in the analysis for which the * filter returns truthy result. E.g. to pre-exclude weakly saturated or * dark colors etc. The second arg is the index of the pixel in the image's * pixel buffer. * * If omitted, all pixels will be included (default). */ filter: Fn2<Float32Array, number, boolean>; } /** * Takes a {@link FloatBuffer} and applies k-means clustering to extract the * `num` dominant colors from the given image. The clustering can be configured * via optionally provided `opts`. Returns array of `{ color, area }` objects * (sorted by descending area), where `color` is a cluster's dominant color and * `area` the normalized cluster size. * * @remarks * This function is syntax sugar for {@link dominantColorsArray}. * * See thi.ng/k-means for details about clustering implementation & options. * * @param img - * @param num - * @param opts - */ export declare const dominantColors: (img: FloatBuffer, num: number, opts?: Partial<DominantColorOpts>) => { color: number[]; area: number; ids: number[]; }[]; /** * Similar to {@link dominantColors}, but accepting an array of color samples * instead of a `FloatBuffer` image. * * @param num * @param samples * @param opts */ export declare const dominantColorsArray: (num: number, samples: NumericArray[], opts?: Partial<KMeansOpts>) => { color: number[]; area: number; ids: number[]; }[]; //# sourceMappingURL=index.d.ts.map