Using a crisp portion of the image to recreate the PSF

I am trying to untie the blurry segments of the following image.

Image with blurred parts

the original PSF was not given, so I started to analyze the blurry part and see if there was a word that I could roughly parse. I found out that I can see "from" in a blurry section. I have cut out both the blur "from" and its counterpart in the clear section as shown below.

Blurred-unblurred comparison

Then I thought of lectures in FFT that you would split the blurred (frequency domain) special blur 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 restored. Please advise how I could have done 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 doesn't work and I get 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?

+3


source to share


1 answer


I'm not an expert in this area, but I played around with deconvolution a bit and wrote a program to calculate the spread function for a clear image and a blurry image. After I got the psf function with this program, I made sure it was correct by using it to deconvolve the blurry image and it worked fine. The code is below. I know this post is very old, but hopefully someone else will find it useful.



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() 

      

0


source







All Articles