3

I'm trying to unblur the blurred segments of the following picture.

Image with blurred parts

the original PSF was not given, so I proceeded to analyze the blurred part and see whether there was a word I could roughly make out. I found out that I could make out "of" in the blurred section. I cropped out both the the blurred "of" and its counterpart in the clear section, as seen below.

Blurred-unblurred comparison

I then thought through lectures in FFT that you divide the blurred (frequency domain) with a particular blurring function (frequency domain) to recreate the original image.

I thought that if I could do Unblurred (frequency domain) \ Blurred(frequency domain), the original PSF could be retrieved. Please advise on how I could do this.

Below is my code:

img = im2double(imread('C:\Users\adhil\Desktop\matlab pics\image1.JPG'));
Blurred = imcrop(img,[205 541 13 12]);
Unblurred = imcrop(img,[39 140 13 12]);

UB = fftshift(Unblurred);
UB = fft2(UB); 
UB = ifftshift(UB); 

F_1a = zeros(size(B));
for idx = 1 : size(Blurred, 3)
    B = fftshift(Blurred(:,:,idx));
    B = fft2(B); 
    B = ifftshift(B);

    UBa = UB(:,:,idx);
    tmp = UBa ./ B; 
    tmp = ifftshift(tmp); 
    tmp = ifft2(tmp); 
    tmp = fftshift(tmp); 
    [J, P] = deconvblind(Blurred,tmp);    

end

subplot(1,3,1);imshow(Blurred);title('Blurred');
subplot(1,3,2);imshow(Unblurred);title('Original Unblurred');
subplot(1,3,3);imshow(J);title('Attempt at unblurring');

This code, however, does not work, and I'm getting the following error:

Error using deconvblind
Expected input number 2, INITPSF, to be real.

Error in deconvblind>parse_inputs (line 258)
validateattributes(P{1},{'uint8' 'uint16' 'double' 'int16' 'single'},...

Error in deconvblind (line 122)
[J,P,NUMIT,DAMPAR,READOUT,WEIGHT,sizeI,classI,sizePSF,FunFcn,FunArg] = ...

Error in test2 (line 20)
    [J, P] = deconvblind(Blurred,tmp);

Is this a good way to recreate the original PSF?

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
Adhil
  • 1,678
  • 3
  • 20
  • 31

1 Answers1

0

I'm not an expert in this area, but I have played around with deconvolution a little bit and have written a program to compute the point spread function when given a clear image and a blurred image. Once I got the psf function using this program, I verified that it was correct by using it to deconvolve the blurry image and it worked fine. The code is below. I know this post is extremely old, but hopefully it will still be of use to someone.

import numpy as np
import matplotlib.pyplot as plt
import cv2

def deconvolve(normal, blur):
    blur_fft = np.fft.rfft2(blur)
    normal_fft = np.fft.rfft2(normal)
    return np.fft.irfft2(blur_fft/(normal_fft))

img = cv2.imread('Blurred_Image.jpg')
blur = img[:,:,0]
img2 = cv2.imread('Original_Image.jpg')
normal = img2[:,:,0]

psf_real = deconvolve(normal, blur)


fig = plt.figure(figsize=(10,4))
ax1 = plt.subplot(131)
ax1.imshow(blur)
ax2 = plt.subplot(132)
ax2.imshow(normal)
ax3 = plt.subplot(133)
ax3.imshow(psf_real)
plt.gray()
plt.show() 
DJElectric
  • 349
  • 1
  • 4
  • 18