extirpation
extirpation

Reputation: 41

Image deblurring using MATLAB

I have two images, one is degraded and one is part of the original image. I need to enhance the first image by using the second one, and I need to do this in the frequency domain. I cut the same area from the degraded image, took its FFT, and tried to calculate the transfer function, but when I applied that function to the image the result was terrible.

So I tried h=fspecial('motion',9,45); to be my transfer function and then reconstructed the image with the code given below.

im = imread('home_degraded.png');
im = rgb2gray(im);
h = fspecial('motion',9,45);
H = zeros(519,311);
H(1:7,1:7) = h;
Hf = fft2(H);
d = 0.02;
Hf(find(abs(Hf)<d))=1;
I = ifft2(fft2(im)./Hf);
imshow(mat2gray(abs(I)))

I have two questions now:

  1. How can I generate a transfer function by using the small rectangles (I mean by not using h=fspecial('motion',9,45);)?

  2. What methods can I use to remove noise from an enhanced image?

Enter image description here

Upvotes: 4

Views: 9802

Answers (2)

opb
opb

Reputation: 161

Basically what you want to do has two steps (at least) to it:

  1. Estimate the PSF (blur kernel) by using the patch of the image with the squares in it.
  2. Use the estimated kernel to do deconvolution to your blurry image

If you want to "guess" the PSF for step 1, that's fine but it's better to calculate it.

For step 2, you MUST first use edgetaper which will subside the ringing effects in your image, which you call noise.

The you use non-blind deconvolution (step 2) by using the function deconvlucy following this syntax:

J = deconvlucy(I,PSF)

this deconvolution procedure adds some noise, especially if your PSF is not 100% accurate, but you can make it smoother if you allow for more iterations (trading in details, NFL).

For the first step, if you don't care about the fact that you have the "sharp" square, you can just use blind deconvolution deconvblind and get some estimate for the PSF. If you want to do it correctly and use the sharp patch then you can use it as your data term target in any optimization scheme involving the estimation of the PSF.

Upvotes: 0

user1830493
user1830493

Reputation: 51

I can recommend you a few ways to do that:

  1. Arithmetic mean filter:

    f = imfilter(g, fspecial('average', [m n]))
    
  2. Geometric mean filter

    f = exp(imfilter(log(g), ones(m, n), 'replicate')) .^ (1/(m*n))
    
  3. Harmonic mean filter

    f = (m*n) ./ imfilter(1 ./ (g + eps), ones(m, n), 'replicate');
    

    where n and m are size of a mask (for instance, you can set m = 3 n = 3)

Upvotes: 5

Related Questions