-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeconvolution.py
67 lines (44 loc) · 1.11 KB
/
deconvolution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import numpy as np
import scipy
from scipy.fftpack import fftshift, ifftshift, fft2, ifft2
from astropy.io import fits
import imreg_dft
import tools
import aperture
import PD
import noise
import wavefront
import wavefront
from wavefront import *
import tools
from tools import *
from noise import *
def ft2(g):
G = fftshift(fft2(ifftshift(g)))
return G
def ift2(G):
numPixels = G.shape[0]
g = fftshift(ifft2(ifftshift(G)))
return g
def conv2(g1, g2):
G1 = ft2(g1)
G2 = ft2(g2)
G_out = G1*G2
numPixels = g1.shape[0]
g_out = ift2(G_out)
return g_out
def richardsonLucy(img, psf, iterations=100):
f = img
blur_psf = np.matrix(psf)
psf_mirror = blur_psf.T
for _ in range(iterations):
f = f * conv2(img / conv2(f, blur_psf), psf_mirror)
return np.abs(f)
def Wienerfilter(img,t0,reg,cut_off,size,ap):
temp = noise_mask_high(size,cut_off)
noise_filter = fftshift(temp)
im0 = tools.apo2d(img,ap)
d0 = fft2(im0)
scene = noise_filter*d0*(np.conj(t0)/(np.abs(t0)**2+reg))
scene2 = ifft2(scene).real
return scene2