Skip to main content

peak_to_mean

Function peak_to_mean 

Source
pub fn peak_to_mean(img: &CaptureImage, bg: [u8; 4], eps: u8) -> f32
Expand description

Ratio of the frame’s peak departure from its background luminance to the mean departure over every pixel — the crest factor, and the direct reading of has the population piled onto a few places? (Plan 0085 Phase 1).

A pixel’s departure is |luma - luma(bg)|, and zero for any pixel coverage would not call lit (so 8-bit dither and a vignette’s own gradient do not inflate the denominator). The absolute difference, not the signed one, because a two-tone world draws its figure darker than its ground (ADR-0106) and an ink figure piling up is the same event as a particle field piling up. The mean is taken over every pixel, not over the lit ones — that is what makes concentration visible. Move a fixed amount of contrast from many pixels into few and the sum barely changes while the peak rises, so the ratio rises with it; spread it back out and it falls toward 1.0.

Range: 1.0 for a perfectly uniform lit frame, up to the frame’s pixel count for a single lit pixel, and exactly 0.0 for a frame that does not depart from its own background at all — an empty picture makes no claim about concentration, the same convention tonal_flatness uses. Total by construction: the peak is itself part of the sum, so a non-zero peak guarantees a non-zero denominator.

It saturates, and a caller must know that. The peak is 8-bit, so once the brightest pixel reaches white the numerator stops growing and further piling registers only through the falling mean. Read it as a trend — which is why the horizon mode reports a series and never a threshold (ADR-0099).