UNPKG

@thi.ng/tensors

Version:

0D/1D/2D/3D/4D tensors with extensible polymorphic operations and customizable storage

69 lines 2.56 kB
import type { Range1_24 } from "@thi.ng/api"; import type { ITensor, ITensor1 } from "./api.js"; /** * Computes the histogram of given uint-based tensor. Returns histogram as a 1D * tensor of `u32` values. The `depth` param defines the value range (as number * of bits) of the input values (max. 24 bits). The optional `mask` and `shift` * params are used to transform input values like so: `(x >>> shift) & mask`. * This allows extracting sub-ranges from a packed integer representation (e.g. * indidivual color channels from a pixel buffer). * * @remarks * Also see {@link equalizeHistogram} and {@link applyLUT}. * * @example * ```ts tangle:../export/histogram-uint.ts * import { histogramUint, tensor } from "@thi.ng/tensors"; * * const src = tensor("u8", [3,3], { data: [12,4,4, 16,16,32, 64,48,4] }); * * // compute histogram with input value range = 8 bits * const hist = histogramUint(src, 8); * * console.log(hist.data); * // Uint8Array(256) [ * // 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, * // 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, * // 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, * // 1, 0, 0, 0, 0, 0, 0 ... * // ] * ``` * * @param src * @param depth * @param mask * @param shift */ export declare const histogramUint: (src: ITensor, depth: Range1_24, mask?: number, shift?: number) => ITensor1<number>; /** * Takes a 1D tensor containing a histogram (e.g. obtained via * {@link histogramUint}) and applies histogram equalization by first * normalizing the histogram, computing its cumulative distribution (via * {@link cdf}), determining the used min/max input value range and then * rescaling values to produce a lookup table (LUT) for remapping input values * via {@link applyLUT}. * * @remarks * References: * * - https://en.wikipedia.org/wiki/Histogram_equalization * * @param out * @param src * @param depth * @param numSamples * @param threshold */ export declare const equalizeHistogram: (out: ITensor1 | null, src: ITensor1, depth: number, numSamples: number, threshold?: number) => ITensor1; /** * Applies given lookup table to `a` and writes results to `out`. I.e. `out[i] = * lut[a[i]]`. This is intended as last step of a histogram equalization process * to transform `a` via applying the histogram obtained via * {@link equalizeHistogram}. * * @param out * @param a * @param lut */ export declare const applyLUT: (out: ITensor | null, a: ITensor, lut: ITensor1) => import("./api.js").ITensor0<number>; //# sourceMappingURL=histogram.d.ts.map