The coding goal of this lab is to learn how to "undo" image deterioration. Concretely, how to get a sharp image out of a blurred one.
The understanding goal is to fully understand the role of convolution in image formation. We also touch the convolution theorem, fourier pair of a rectangle function and the problem of noise in images.
We were discussing the convolution during the lecture.The creation of an image g can be described by means of convolution as g = f*h, where f denotes the unknown ideal image and h denotes the convolution kernel of the camera.
The ideal camera | An unfocused camera | A moving camera, steady movement in one direction |
Assume that we know that the image deterioration was caused by a steady camera motion during acquisition (shutter open). To know the "camera" completely we have to estimate the direction and duration of the motion. Both values can be, with some luck, extracted from the Fourier image of the deteriorated image. Remember that due to the convolution theorem, the convolution of the spatial signals can be described in terms of multiplication their Fourier images, G=FH.
im |
log(im_Pfft + 1) |
median(log(im_Pfft + 1)) |
What you see in the center image is the product of Fourier image of the ideal image and the Fourier image of the rectangle function that coused the blur. Remember that the Fourier image of the rectangle function is a sinc function and that its period depends on the length of the rectangle function.
Once we know all the parameters we can create a convolution kernel h, computes its Fourier pair H and undo the deterioration by F=G/H.
Even if you are quite sure that the implementation is ok, it may happen the results are unsatisfactory, horrible indeed. The reason can be the noise in the input image. One source of the noise is surely the rounding error during quantization. Let extend the simple image creation model to incluide also the noise g = f*h + n, where n is some unknown noise. The deconvolution process (in Fourier domain) is then F = G/H + N/H. The additive term N/H can be quite big. It may happen that the modulus of H decreases faster than N and that the noise prevails over the useful information.
To regularize the method we may extend the basic deconvolution to Wiener
filtration
F =
H
|H|2 + KG ,
Please use the demo codes wisely. Do not get trapped in playing with. The demos just demostrate some elementary handling of Fourier images and the implementation of simple filtration in frequency space.