Module imagery.analysis.rgb_histogram

Image-domain per-channel histograms and basic ROI statistics for decoded u8 RGB pixels. A raster-d view provides storage, layout and borrow safety. No colour transform, luminance conversion, calibration or NoData inference.

Functions

NameDescription
tryRgbCumulativeCounts(histogram, published) Compute inclusive cumulative counts for each stored RGB byte, through that byte. At index 255 each channel equals includedPixels. The result remains all zero for a valid all-excluded histogram. A malformed public record (any channel total differs from includedPixels) returns false and leaves published unchanged. No raster access or allocation occurs.
tryRgbEqualizationLut(histogram, published) Build a separate equalization lookup table for each stored RGB8 channel. For a nonconstant channel, the first observed byte maps to 0 and each later byte maps to roundHalfUp(255 * (CDF(byte) - CDF(first)) / (includedPixels - CDF(first))). Bytes before the first observed byte map to 0. A channel with only one observed byte gets an identity table, so a flat channel is not arbitrarily recoloured. Integer arithmetic is exact through the full ulong count domain; no floating-point CDF is formed.
tryRgbHistogram256(rgb, roi, published) Build stored 8-bit R, G and B channel histograms over a nonempty ROI. This image-specific operation accepts exactly three channels already interpreted by the caller as R, G, B in that order. Planar, interleaved and signed-stride raster views are read through raster-d. It does not convert transfer functions, infer alpha, compute luma or assign units.
tryRgbHistogram256(rgb, roi, selection, published) Build the same histogram with an explicit binary pixel-inclusion mask.
tryRgbHistogram256WithValidity(rgb, roi, validity, published) Build an RGB histogram using an explicit validity/NoData mask.
tryRgbPercentile(histogram, percentile, published) Find each channel's nearest-rank stored-byte percentile. The percentile is an integer from 0 through 100. Zero selects the minimum observed byte; for 1..100 the one-based rank is ceil(percentile * includedPixels / 100). The smallest byte whose cumulative count reaches that rank is returned. This is a discrete order statistic with no interpolation or colour-space conversion. An empty selection, percentile above 100, or malformed public record returns false and leaves published unchanged. The computation is exact for the full ulong count domain without an overflowing product. No raster access or allocation occurs.
tryRgbPercentileStretchLut(histogram, lowerPercentile, upperPercentile, published) Build a per-channel RGB8 contrast-stretch lookup table from two observed nearest-rank percentiles. Each channel maps its lower observed byte to 0, its upper observed byte to 255, and clamps outside that interval. Interior bytes use linear interpolation rounded to nearest integer, with ties up. If both percentiles select the same byte in a channel, that channel's entire table is the identity: no arbitrary black/white choice is made.

Structs

NameDescription
RgbHistogram256 Exact 256-bin stored-byte distributions for three channels in R,G,B order. Each channel's bins sum to includedPixels. Excluded pixels contribute only to excludedPixels (not to bins). The two pixel counts add to the nonempty ROI area.

Enums

NameDescription
RgbHistogramError Explicit RGB histogram result status. Only none means published success; .init == notAttempted, and no public call returns notAttempted. Any normally returned failure preserves the caller's previous result.