Apply a known blur¶
| Fact | Value |
|---|---|
| Also called | Known blur, Blur with a PSF, Point spread function |
| Status | Implemented and tested |
| Family | Utilities |
| Engine | Browser |
| Type | Linear, spatial, convolution with a PSF |
| Output | Image |
| Operator shown as | dynamic-kernel (exact) |
| Support radius | half the PSF size |
| Code | web/src/core/filters/restoration/deconvolve.ts, degradeBlurFilter |
| Operator code | web/src/core/filters/restoration/deconvolve.ts, psfKernel |
| Channels | RGB, Brightness only |
Overview¶
Apply a known blur blurs the image with a Gaussian, motion or defocus point spread function, or PSF. The PSF is the picture a single bright point turns into. Because the blur is known exactly, the deconvolution filters can be tested on the result, with the same blur settings.
How it works¶
- Choose the blur and its size.
- The filter builds the PSF kernel.
- Each pixel becomes the sum of its neighbors weighted by the kernel.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(f, g\): The image and the blurred image
- \(h\): The point spread function
The image f is convolved with the PSF h. The PSF is the kernel of the Gaussian filter cut at 4 sigma, of the motion blur filter, or of the disk averaging filter. All three are symmetric under a half turn, so convolution and correlation give the same result. Use the same blur settings in a deconvolution filter to undo it.
A linear, shift-invariant blur is a convolution g = h * f of the image f with the PSF h. The Gaussian PSF is the kernel of the Gaussian filter, cut at 4 sigma here so its tail is kept. The motion PSF is the kernel of the motion blur filter, with weights proportional to the length of the line in each cell. The defocus PSF is the disk kernel of the disk averaging filter. All three are symmetric under a half turn, so convolution and correlation are the same.
Kernel or operator¶
The Inspector shows the PSF kernel for the current settings.
Algorithm¶
- Build the PSF kernel for the chosen blur.
- Correlate the image with it, with the border mode at the edges.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Blur psf |
Gaussian | Gaussian, Motion, Defocus | The point spread function, the picture a single bright point turns into. |
Sigma sigma |
2 | 0.3 to 10 px | The standard deviation of the Gaussian blur. The PSF ends at 4 sigma. |
Motion length length |
9 | 1 to 51 px | The length of the straight motion, for motion blur. |
Motion angle angle |
0 | 0 to 180 deg | The direction of the motion, counterclockwise from the x axis, as for motion blur. |
Defocus radius radius |
3 | 0.5 to 15 px | The radius of the defocus disk. |
Border mode border |
Reflect 101 (default) | Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap | How pixels outside the image are filled when the window reaches past the edge. |
Channels channelScope |
RGB | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
degradeBlurFilter in web/src/core/filters/restoration/deconvolve.ts builds the kernel with psfKernel and correlates the image with it. It runs through the shared framework in web/src/core/filters/run.ts, which handles the border, the channel scope and alpha.
Worked example¶
| Row | x -2 | x -1 | x 0 | x 1 | x 2 |
|---|---|---|---|---|---|
| -2 | 0 | 0 | 0 | 0 | 0 |
| -1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0.200 | 0.200 | 0.200 | 0.200 | 0.200 |
| 1 | 0 | 0 | 0 | 0 | 0 |
| 2 | 0 | 0 | 0 | 0 | 0 |
The PSF for motion of length 5 at angle 0: one row of five equal weights that add up to 1. Each pixel becomes the mean of itself and its two neighbors on each side along x.
Complexity¶
- Time: \(O(N k^2)\)
- Memory: \(O(N)\)
N is the number of pixels and k the side of the PSF kernel.
Artifacts and limitations¶
Limitations
- Real blur often changes across the image. This blur is the same everywhere.
Artifacts
- None beyond the blur itself.
Tests¶
The reference uses scipy.ndimage.correlate with the same kernels. The cases cover the three blurs with two border modes.
References¶
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Chapter 5, image restoration and reconstruction.