Skip to main content

estimate_noise_sigma_u8

Function estimate_noise_sigma_u8 

Source
pub fn estimate_noise_sigma_u8(img: &[u8], w: usize, h: usize) -> Option<f32>
Expand description

Estimate the standard deviation of the pixel noise in an 8-bit grayscale image, in gray levels.

Measures the noise as it appears in the 8-bit image, so the estimate includes the rounding to integers (1/12 gray level² when the noise spans several levels). It is designed for images dominated by strong edges, such as calibration boards: edges, corners and smooth shading are excluded from the statistic, and so are areas within 12 gray levels of black or white, where clipping removes noise. Under signal-dependent noise the estimate is the root of the mean noise variance over the image’s structure-free areas.

For white noise it is the noise standard deviation; adding white noise of variance σₐ² raises its square by σₐ². It is not reliable for spatially correlated noise: on Bayer-demosaiced images it reads the demosaicing pattern along edges (about 4 gray levels whatever the noise), and on JPEG images of a dense board it usually returns None, because almost every 8×8 block holds an edge. Supply the noise level for such images instead, measured on the delivered images (for example from two frames of a static scene).

Accuracy on synthetic boards with white noise (cells 5–12, any rotation or shear, blur up to 2.5 px): within about 4% for σ ≥ 2 gray levels and 5% for σ ≥ 1 (12% on images with very few structure-free areas). Below 1 gray level, residual pattern in strongly blurred images is comparable to the noise and reads up to about 20% high. Images with almost no structure-free area — small, sharp or slightly blurred cells filling the whole frame — give no estimate at low noise and can read high (up to 2×) at very high noise.

Deterministic and cheap: it samples about 8 000 4×4 windows on a regular grid, so the cost does not grow with the image size (under 0.1 ms per frame); only an image where too few of them are free of edges is sampled once more, four times as densely.

Returns None when the image is smaller than 4×4 or too few windows (fewer than 512) are free of edges.

§Panics

Panics if img.len() != w * h.