0

I recently used a Gaussian convolution to blur an image. It works well, in fact it works excellently. However, now I'm trying to reverse it and my inverse filter keeps running into problems. The filter is supposed to run on the following principle:

G(x, y) / H(x, y) = F(x, y) where G(x, y) is the Fourier transform of the blurred image, H(x, y) is the Fourier transform of the blurring function and F(x, y) is the Fourier transform of the original image.

Currently, the resulting image looks exactly the same as the original. My algorithm is as follows:

from PIL import Image
import math
import cmath
import numpy as np

def reverseGaussianBlur(picture, r):
    rs = int(math.ceil(r * 2.57)                  # Calculate significant radius
    w, h = picture.size
    pixels = list(picture.getdata())              # Image's pixels as list
    fft_pixels = runFourier(pixels, False)        # Run FFT
    temp_picture = []
    for u in range(0, h):
        for v in range(0, w):
            val = [0] * 3
            wsum = 0
            for iy in range(u - rs, u + rs + 1):
                y = min(h - 1, max(0, iy))
                for ix in range(v - rs, v + rs + 1):
                    x = min(w - 1, max(0, ix))
                    weight = (2 * math.pi) ** 0.5 * cmath.exp(-r * r * ((ix - v) * 
                        (ix - v) + (iy - u) * (iy - u)) / 2)
                    if (weight.real > 1e-5):
                        val = [n + p / weight for n, p in zip(val, fft_pixels[y * w + x])]
                    wsum += weight
            temp_picture.append(tuple([v * wsum for v in val]))
    return_picture = [tuple(int(round(p)) for p in pixel) for pixel in 
        runFourier(temp_picture, True)]           # Run Inverse FFT
    return return_picture

Anyway, I'm not quite sure what's wrong and any help would be great.

Woody1193
  • 7,252
  • 5
  • 40
  • 90
  • "In practice the results are often quite disappointing " according to Yves Daoust in http://stackoverflow.com/questions/21791982/reverse-image-blur-filter-not-unsharp-mask. He suggests using a Weiner filter. –  Aug 04 '15 at 13:28
  • If it were a matter of reversing blurring caused by some sort of natural phenomenon, I would be accepting of it, but I caused the blurring in the first place. It seems I should be able to undo it, but then again, maybe too much information was lost when I blurred the image. – Woody1193 Aug 04 '15 at 14:03

1 Answers1

3

When you blur an image, you're basically removing the high frequency components. They're gone. There is no reverse filter. If you had applied a "filter" that took each pixel and replaced it with flat white, you wouldn't expect there to be a reverse filter for that, because all the details (except the size of the the original image) are lost. It's the same thing with blurring, only you've lost just the high frequency components.

Hashman
  • 367
  • 1
  • 10