Deblurring using inverse filtering doesn't work

Viewed 48

I have a group project where we have to implement a Wiener Filter. But despite trying everything we can't find a way to make anything work...

For now we would just love to manage to use inverse filtering. Even when we decide to take the source code from a site explaining the filter and translate it to python, it still doesn't work...

The code from the site:

N=256;
n=.2;
f=freadbin('lenna.256',N,N);
figure(1)
imagesc(f)
colormap(gray)
b=ones(4,4)/4^2;
F=fft2(f);
B=fft2(b,N,N);
G=F.*B;
g=ifft2(G)+10*randn(N,N);
G=fft2(g);
figure(2)
imagesc(abs(ifft2(G)))
colormap(gray)
BF=find(abs(B)<n);
%B(BF)=max(max(B))/1.5;
B(BF)=n;
H=ones(N,N)./B;
I=G.*H;
im=abs(ifft2(I));
figure(3)
imagesc(im)
colormap(gray)

Our code :

    f, axes = plt.subplots(1, 3, figsize=(30,45))

    img = rgb2gray(plt.imread('lena256.jpg'))

    N = 256
    n = 0.2
    f = img
    axes[0].imshow(f, cmap='gray')

    b = np.ones((4, 4)) / (4 * 4)
    F = fft2(f)
    B = fft2(b, s=(N, N))
    G = np.multiply(F, B)
    g = ifft2(G) #+ 10 * np.random.randn(N, N)
    G = fft2(g)

    axes[1].imshow(np.abs(ifft2(G)), cmap='gray')

    # %B(BF)=max(max(B))/1.5 ???

    B[np.abs(B) < n] = n
    H = np.divide(np.ones((N, N)), B)

    I = np.multiply(G, H)
    im = np.abs(ifft2(I))
    axes[2].imshow(im, cmap='gray')

Our output.

Which is far from being as good as what the site shows.

Thank you for your time

1 Answers

Ok it was simply the n that was too big. When I tried to put n = 0.00000001 it worked fine !

Related