return ws[np.argmin([mse(x, deconv_wiener(y, h, w)) for w in ws])] if __name__ == "__main__": np.random.seed(0) # 2d from matplotlib.pyplot import imread s = 0.05 x = imread("data/usaf.png") x *= 0 x[200:400, 200:400] = 1.0 mu = 10000.0 rho = 10.0 scale = 100 x *= 1.0 * scale h = psf(x.shape, (6.0, 6.0)) y = myconvolve(x, h) + s * np.amax(x) * np.random.uniform(0, 1, x.shape) # u = deconv_tv_al([y,y2],[h,h2]) u = deconv_tv_al(y, h, mu, rho) u2 = deconv_wiener(y, h, rho / mu)
def _fun(u , mu): gu = np.array(np.gradient(u)) bu = myconvolve(u ,h) l1_part = np.mean(reduce(np.add,[np.abs(_g) for _g in np.array(np.gradient(u))])) l2_part = np.mean((bu-y)**2) return l1_part + .5*mu*l2_part
#u = deconv_rl([g1,g2,g3],[h1,h2,h3],20, gamma = 0.000001) # a2 = deconv_rl([g1,g2],[h1,h2],10, gamma = 0.000001) # a3 = deconv_rl([g1,g2,g3],[h1,h2,h3],10, gamma = 0.000001) # a4 = deconv_rl([g1,g2,g3,g4],[h1,h2,h3,h4],10, gamma = 0.000001) # # u1 = deconv_rl([g1],[h1],20, gamma = 0.000001) # u2 = deconv_rl([g2],[h2],20, gamma = 0.000001) # u3 = deconv_rl([g3],[h3],20, gamma = 0.000001) # u4 = deconv_rl([g4],[h4],10, gamma = 0.000001) hs = [np.roll(psf_airy(im.shape, _d),2*i,0) for i,_d in enumerate([(10,20),(20,10),(15,15)])] gs = [myconvolve(im ,h)+.1*np.amax(im)*np.random.normal(0,1.,im.shape) for h in hs] u = deconv_rl([gs[0]]*3,[hs[0]]*3,20, gamma = 0.000001, fft_is_unitary=True) # from itertools import product # import pylab # N = len(gs) # u = [] # for i,(g,h) in enumerate(zip(product(gs,repeat=2),product(hs,repeat=2))): # u.append(deconv_rl(g,h,5,gamma = 1.e-5)) # pylab.subplot(N,N,i+1) # pylab.imshow(u[-1])
return f if __name__ == '__main__': from matplotlib.pyplot import imread from pydeconv.utils import myconvolve, psf im = imread("../tests2/data/usaf.png") np.random.seed(0) hx = (5.,5.) h = psf(im.shape,hx) g = myconvolve(im ,h) g += .01*np.amax(im)*np.random.normal(0,1.,im.shape) mu = 10000. rho = 2. def wien(y_f,alpha = .1): u_f = h_f.conjugate()*y_f u_f /= np.abs(h_f)**2 + alpha return np.abs(np.fft.ifftn(u_f)) def _fun(u , mu): gu = np.array(np.gradient(u)) bu = myconvolve(u ,h)