Blind deconvolution¶
| Fact | Value |
|---|---|
| Also called | Blind Richardson-Lucy, Blind RL deconvolution |
| Status | Implemented and tested |
| Family | Restoration and reconstruction |
| Engine | Science engine |
| Type | Nonlinear, iterative, alternating blind Richardson-Lucy deconvolution |
| Output | Image |
| Operator shown as | iterative (exact) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/restoration.py, blind_deconv |
| Operator code | engine/src/pixelnexus_engine/filters/restoration.py, blind_representation |
| Packages | SciPy |
| Channels | Brightness only, RGB |
Overview¶
Blind deconvolution estimates both the sharp image and the blur from one photo. It alternates Richardson-Lucy steps: a few for the blur with the image held still, then a few for the image with the blur held still. This filter is experimental. The pair of image and blur is not unique, and the result depends strongly on the first guess. It runs in the PixelNexus engine on your computer.
How it works¶
- Extend each channel with the border mode, as the frequency filters do.
- Start with the photo as the image and a Gaussian of the chosen sigma as the blur, cut to the support square.
- Run a few Richardson-Lucy steps for the blur, with the image fixed. After each one, keep the support, set negative weights to 0 and scale the sum to 1.
- Run a few Richardson-Lucy steps for the image, with the blur fixed.
- Repeat for the chosen number of cycles, then crop the image, or show the blur.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(g\): The blurred image extended with the border mode
- \(f, f'\): The estimate of the sharp image, and the same turned by a half turn
- \(h, h'\): The estimate of the PSF, and the same turned by a half turn
- \(\Pi\): Keeps the support, sets negative weights to 0 and scales the sum to 1
- \(\sigma\): The sigma of the first Gaussian guess
- \(C\): The number of cycles
A blurred photo g is the sharp image f blurred with the PSF h. Blurring is symmetric in f and h, so the Richardson-Lucy step that improves f with h fixed also improves h with f fixed. Fish, Brinicombe, Pike and Walker alternated the two. Each cycle runs a few steps for the PSF, then a few for the image. f' and h' are f and h turned by a half turn. In the PSF step, f plays the role of the blur, so the sum of f takes the place of the sum of h. After each PSF step, Pi keeps the PSF inside a square of radius r around its center, sets negative weights to 0 and scales the sum to 1. The support and these rules are PixelNexus's choices. Values of h * f below 1e-12 count as 1e-12. The pair of f and h is not unique. The sharp photo with a single bright point as the PSF fits the data perfectly, and a narrow first guess tends to drift there. So the filter is experimental.
A blurred photo is the convolution of the sharp image with the blur. Convolution is symmetric, so the Richardson-Lucy step that sharpens the image for a known blur can also refine the blur for a known image. Fish, Brinicombe, Pike and Walker alternated the two. The trouble is that the problem has too many answers. A single bright point as the blur, with the photo itself as the image, fits the data perfectly. Constraints push the search away from such answers. Here the blur must lie inside a small square, have no negative weights and sum to 1. A wide first guess also helps, since a narrow guess tends to stay narrow. The worked example shows both effects.
Kernel or operator¶
The Inspector asks the engine for the stages with the current settings. They are the start, the PSF steps, the image steps and the number of cycles.
Algorithm¶
- Extend the image with the border mode by half its size, at most 256 pixels, on each side.
- Start with f equal to the extended image and h a Gaussian of sigma, cut to the support.
- Run the PSF steps with f fixed. After each one, apply the support, set negative weights to 0 and scale the sum to 1.
- Run the image steps with h fixed, as in Richardson-Lucy.
- Repeat for the chosen number of cycles.
- Crop the image to its size, or show the PSF.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Output output |
Deblurred image | Deblurred image, Show PSF | The deblurred image, or the estimated PSF, enlarged in the middle of a black image with its largest weight at 255. |
First guess sigma sigma |
3 | 0.3 to 10 px | The first PSF is a Gaussian of this sigma, cut to the support. |
Support radius support |
7 | 1 to 25 px | The PSF is kept inside a square of 2 r + 1 pixels around its center. |
Cycles cycles |
10 | 1 to 100 | How many rounds of PSF steps and image steps to run. |
PSF steps per cycle psfSteps |
5 | 1 to 20 | How many Richardson-Lucy steps update the PSF in each cycle, with the image fixed. |
Image steps per cycle imageSteps |
5 | 1 to 20 | How many Richardson-Lucy steps update the image in each cycle, with the PSF fixed. |
Border mode border |
Reflect | Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap | How pixels outside the image are filled when the window reaches past the edge. |
Channels channelScope |
Brightness only | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
blind_deconv in engine/src/pixelnexus_engine/filters/restoration.py runs blind_deconv_plane on each channel the scope names. blind_rl alternates psf_step and image_step. Both work on the extended grid through the FFT. psf_picture draws the PSF for the Show PSF output. With the brightness scope, one PSF is found for the luma. With the RGB scope, each channel gets its own. There is no live preview. The result arrives when you click Apply.
Worked example¶
| First guess sigma | Start error | Error after | PSNR in dB |
|---|---|---|---|
| 0.5 | 1.55 | 1.55 | 16.08 |
| 1.0 | 0.95 | 0.96 | 16.75 |
| 2.0 | 0.00 | 0.08 | 19.44 |
| 3.0 | 0.56 | 0.27 | 18.23 |
| 5.0 | 1.01 | 0.44 | 16.35 |
A Siemens star of 160 by 160 pixels, blurred with the Gaussian PSF of sigma 2 and the reflect border, with Gaussian noise of sigma 1 from NumPy's default_rng with seed 7. The blurred image has 15.93 dB. The errors are the sum of the absolute differences between the PSF and the true PSF, before and after the default 10 cycles. A narrow first guess barely moves, since the sharp image with a single bright point already fits the photo well. Wider guesses move toward the true PSF.
Complexity¶
- Time: \(O(C (P + I) N log N)\)
- Memory: \(O(N)\)
N is the number of pixels of the extended image, C the number of cycles, and P and I the PSF and image steps per cycle. Each step takes three FFTs.
Artifacts and limitations¶
Limitations
- Experimental. The result depends strongly on the first guess and the support.
- A first guess narrower than the real blur tends to stay narrow, so little changes.
- Noise and large flat areas make the PSF estimate unreliable.
- Assumes one blur for the whole image.
Artifacts
- Ringing next to strong edges when the PSF is too wide.
- Speckles in flat areas after many image steps.
Tests¶
Without noise, the sharp image and the true PSF must be fixed points of both steps. The image step must equal a Richardson-Lucy step written in the test. From a first guess of sigma 3, 40 cycles must bring the PSF at least 30 percent closer to the true PSF of sigma 1.5. The PSF must stay inside its support, non-negative and summing to 1. Show PSF must draw the kernel in the middle with its largest weight at 255. The engine API tests run jobs and check the stages of the representation.
References¶
- Fish, D. A., Brinicombe, A. M., Pike, E. R., and Walker, J. G. Blind deconvolution by means of the Richardson-Lucy algorithm. Journal of the Optical Society of America A 12(1), 58 to 65, 1995. DOI 10.1364/JOSAA.12.000058.
- Richardson, W. H. Bayesian-based iterative method of image restoration. Journal of the Optical Society of America 62(1), 55 to 59, 1972. DOI 10.1364/JOSA.62.000055.
- Lucy, L. B. An iterative technique for the rectification of observed distributions. The Astronomical Journal 79, 745, 1974. DOI 10.1086/111605.