Kalman filter¶
| Fact | Value |
|---|---|
| Also called | Kalman smoother, Row and column Kalman filter |
| Status | Implemented and tested |
| Family | Adaptive and statistical filters |
| Engine | Browser |
| Type | Linear, statistical, Kalman filtering and smoothing |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | the whole image |
| Code | web/src/core/filters/adaptive/scan.ts, kalmanFilter |
| Operator code | web/src/core/filters/adaptive/scan.ts, kalmanFilter |
| Channels | RGB, Brightness only |
Overview¶
The Kalman filter estimates a signal that follows a known model from noisy measurements. Here each row of the image is the signal. The model says that the next clean value is the last one times rho, plus a small change. The filter blends this guess with the noisy pixel, and trusts the pixel less the noisier the image is. A Rauch-Tung-Striebel smoother then runs back along the row, so each estimate also uses the pixels after it. The columns of the noisy image get the same, and the result is the mean of both runs.
This separable form is PixelNexus's own. The reduced update Kalman filter of Woods and Radewan uses a model in two dimensions, which this filter does not.
How it works¶
- Along a row, guess the next clean value from the last one.
- Blend the guess with the noisy pixel. The noisier the image, the more the guess counts.
- Run back along the row, so every pixel also learns from the pixels after it.
- Do the same on the columns, and take the mean of both.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(y_k\): The pixel, with the image mean taken off
- \(x_k\): The clean value
- \(\rho\): The correlation of neighboring values
- \(\sigma_v\): The noise sigma
- \(P_k^-, P_k\): The variance of the prediction and of the estimate
- \(K_k\): The Kalman gain
- \(\hat{x}_k^{s}\): The smoothed estimate
Along a row, the clean value x follows a first-order autoregressive model with correlation rho. Each pixel y adds white noise v of variance sigma_v^2. The prediction is x_k^- = rho x_(k-1). Its variance is P_k^- = rho^2 P_(k-1) + q, with q = sigma_x^2 (1 - rho^2). The Kalman gain K weighs the prediction against the pixel. The Rauch-Tung-Striebel smoother then runs back along the row, so each estimate also uses the pixels after it. Rho and the signal variance sigma_x^2 come from the image. The signal variance is the variance of the lines minus the noise variance. Rho comes from the covariance of neighbors, which white noise does not change. The columns of the noisy image get their own model and run, and the result is the mean of the row and column runs. This separable form is PixelNexus's own.
The Kalman gain K is the share of the new pixel in the estimate. When the prediction is uncertain, P^- is large and K is near 1, so the pixel counts most. When the noise is large, K is small, and the prediction counts most. For this model the Kalman filter gives the estimate with the least mean squared error among all linear estimates.
The model needs rho and the signal variance. White noise adds its variance to the variance of the pixels, but not to the covariance of neighbors. So the filter takes the noise variance off the pixel variance, and divides the neighbor covariance by the result to get rho.
The first design ran the columns of the row result. That was tried and rejected. After the row pass the image looks almost free of noise along the columns, so rho came out as 1, and the edges blurred far along the columns.
Kernel or operator¶
There is no fixed kernel. The gain changes along each line. The Inspector shows the model, the filter and the smoother.
Algorithm¶
- Estimate the mean, rho and the signal variance of the rows, and of the columns.
- On each row, run the Kalman filter forward and the smoother back.
- On each column of the noisy image, do the same.
- Write the mean of the two results.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Noise sigma sigma |
20 | 0.5 to 100 | The standard deviation of the noise, in 8-bit levels. |
Implementation¶
kalmanPlane in web/src/core/filters/adaptive/scan.ts estimates one model for the rows and one for the columns with arModel. kalmanLine runs the filter forward and the smoother back on one line. Each line starts from the image mean, with the signal variance as its uncertainty. The filter needs whole lines, so it runs on the whole image at once.
Worked example¶
| Method | Disks (dB) | Stripes (dB) |
|---|---|---|
| Noisy, sigma 20 | 22.60 | 22.15 |
| Box 3x3 | 26.54 | 17.97 |
| Mean of the 8 neighbors (2D LMS, mu 0) | 25.63 | 16.96 |
| 2D LMS, 3x3, mu 0.05 | 25.05 | 24.83 |
| 2D RLS, 3x3, lambda 0.999 | 25.77 | 25.89 |
| Kalman, sigma 20 | 26.48 | 23.15 |
PSNR against the clean images, 96 x 96: the Disks and dots test image, and diagonal stripes with a period of 6 pixels. Gaussian noise of sigma 20, seeds 41 and 42.
On the disks, the Kalman filter is as good as a box filter, with the noise level as its only setting. On the stripes it keeps more than any fixed average, since its model follows the steep changes along each line. The adaptive predictors do better there.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels per channel. A few multiplications per pixel and pass.
Artifacts and limitations¶
Limitations
- One model for the whole image. Edges are smoothed like flat areas.
- The separable model is simpler than a true two-dimensional image model.
Artifacts
- Soft edges, since one model covers the whole image.
Tests¶
A NumPy version of the same model, filter and smoother, in tools/fixtures_scan.py, gives the reference for noise sigma 5, 20 and 40. Before it is used, the script checks that a noise sigma near 0 gives the image back.
References¶
- Kalman, R. E. A new approach to linear filtering and prediction problems. Journal of Basic Engineering 82(1), 35 to 45, 1960. DOI 10.1115/1.3662552.
- Rauch, H. E., Tung, F., and Striebel, C. T. Maximum likelihood estimates of linear dynamic systems. AIAA Journal 3(8), 1445 to 1450, 1965. DOI 10.2514/3.3166.