Steering kernel regression¶
| Fact | Value |
|---|---|
| Also called | Iterative steering kernel regression, SKR, Adaptive kernel regression |
| Status | Implemented and tested |
| Family | Adaptive and statistical filters |
| Engine | Science engine |
| Type | Nonlinear, spatial, adaptive kernel regression |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | radius x iterations, plus 2 per iteration for the gradient window |
| Code | engine/src/pixelnexus_engine/filters/steering_kernel.py, steering_kernel |
| Operator code | engine/src/pixelnexus_engine/filters/steering_kernel.py, steering_kernel_representation |
| Packages | NumPy |
Overview¶
Steering kernel regression, by Takeda, Farsiu and Milanfar, removes noise by fitting a small polynomial surface around each pixel. The fit weights the neighbors with a kernel shaped by the local edges. Near an edge the kernel is long and thin along it, so the fit averages along the edge and not across it. In a flat area the kernel is wide and round. The kernel shapes come from the gradients of the image, and they are estimated again from each result for a few iterations. The filter runs in the PixelNexus engine, in PixelNexus's own code.
How it works¶
- Estimate the gradients with a classic kernel regression.
- From the gradients in a 5 x 5 window around each pixel, build its steering matrix.
- Fit a weighted polynomial around each pixel with the steered kernels, and keep the constant term.
- Repeat from the gradients of that fit, on its result, for the chosen number of iterations.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(y_i\): The sample at position x_i
- \(\beta_0\): The estimate at x
- \(\beta_1\): The gradient at x
- \(C_i\): The steering matrix of sample i
- \(h\): The global smoothing parameter
- \(s_1, s_2\): The singular values of the local gradients
- \(M\): The number of gradients in the local window, 25
At each pixel x, a polynomial is fitted to the nearby samples y_i by weighted least squares, and the constant term beta_0 is the result. The weights come from a Gaussian kernel shaped by C_i, the steering matrix of each sample. C_i is built from the gradients in a small window around the sample. Its rotation follows the dominant edge direction. Its elongation sigma_i = (s_1 + 1) / (s_2 + 1) grows with the gap between the two singular values of the gradients. Its scale gamma_i = sqrt((s_1 s_2 + 0.01) / M) makes the kernel large in flat areas and small in textured ones. Each iteration estimates the gradients again from the last result.
Kernel regression treats the image as samples of an unknown smooth function. Near each pixel, it fits a polynomial of order N by weighted least squares. The constant term is the estimate, and the linear terms are the gradient. Classic kernel regression uses the same round kernel everywhere, so it blurs edges. The paper shows that the bilateral filter is the same fit of order 0, with a kernel that also weights brightness.
The steering kernel adapts the shape instead. For each sample, the gradients in a small window form a matrix G. Its two singular values s_1 and s_2 measure the energy along the main gradient direction and across it. On an edge, s_1 is much larger than s_2, so the kernel gets long along the edge. In a flat area both are small, so the kernel is round, and its scale gamma makes it large.
Kernel or operator¶
Each pixel has its own kernel, so there is no fixed one. The Inspector asks the engine for the stages with the current settings.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Smoothing h h |
2 | 0.5 to 5 | The global smoothing parameter h of the kernel. 2.0 as in the paper's experiments on JPEG artifacts and film grain. |
Regression order N order |
2 (local quadratic) | 0 (weighted average), 1 (local plane), 2 (local quadratic) | The order of the local polynomial. The paper's denoising experiments use 2. |
Iterations iterations |
3 | 1 to 10 | How many times the kernels are estimated again and the regression repeated. The paper uses 3 for real noise and 7 for strong Gaussian noise. |
Window radius radius |
5 | 2 to 8 px | The regression window is 2 radius + 1 pixels on each side. Our choice of 5, since the paper does not give its window. |
Channels channelScope |
RGB | RGB, Each channel separately, Brightness only, Color only | Which part of the color image the filter changes. |
Implementation¶
steering_kernel in engine/src/pixelnexus_engine/filters/steering_kernel.py follows Section III of the paper and its Fig. 10. It sums the weighted normal equations over the window with NumPy, and solves one small system per pixel with numpy.linalg.solve. The singular values of G come from the eigenvalues of the 2 x 2 matrix G^T G, which gives the same C_i as the paper's SVD. The regularization values lambda' = 1.0 and lambda'' = 0.01 are the paper's. The first gradients come from a classic regression with the same h and order, at least 1. The paper names this start but not its settings, so that is our choice, as are the window sizes and the border.
Worked example¶
| Method | Order N | Iterations | RMSE (levels) |
|---|---|---|---|
| Noisy | 20.15 | ||
| Classic | 2 | 19.04 | |
| Steering | 0 | 1 | 11.76 |
| Steering | 0 | 3 | 13.59 |
| Steering | 0 | 5 | 17.25 |
| Steering | 0 | 7 | 19.76 |
| Steering | 2 | 1 | 10.79 |
| Steering | 2 | 3 | 10.79 |
| Steering | 2 | 5 | 11.83 |
| Steering | 2 | 7 | 12.50 |
The image of the figure, 120 x 120, with h 2 and a window of 11 x 11. The RMSE is measured against the image before noise, over all pixels.
The thin lines dominate the error, since classic regression spreads them into wide bands. That is why its RMSE, 19.04, is close to the noisy input. Steering regression keeps the lines and roughly halves the error. More iterations do not always help. At order 2 the error is lowest after 1 to 3 passes, and at order 0 after 1. The paper notes the same trade: each pass removes noise but adds blur, and its best results took 3 to 7 passes.
Complexity¶
- Time: \(O(N R^2 K)\)
- Memory: \(O(N)\)
N is the number of pixels, R the window side and K the number of iterations.
Artifacts and limitations¶
Limitations
- Slower than the bilateral filter, since each pixel solves a small least squares system.
- Too many iterations blur fine detail.
Artifacts
- Painterly streaks along strong edges with many iterations.
- Small wiggles in flat areas at low noise, where the gradients are mostly noise.
Tests¶
At order 0, the classic regression must equal a normalized Gaussian average. At order 2, both the classic and the steered fit must give back a quadratic surface and its gradient to 1e-6. The steering matrix must equal the one built from an SVD exactly as in Eq. 50 to 54. A flat area must get the round kernel of scale sqrt(0.01 / 25). On a straight edge, the narrow direction must lie along the gradient, with the ratio (s_1 + 1)^2. On a noisy edge, the result must beat classic regression and keep the edge sharper. Order 0 and the progress reports are checked too.
References¶
- Takeda, H., Farsiu, S., and Milanfar, P. Kernel regression for image processing and reconstruction. IEEE Transactions on Image Processing 16(2), 349 to 366, 2007. DOI 10.1109/TIP.2006.888330.