def get_best_wiener(y, h, Nws=50): ws = 1.0e-6 * 2 ** np.arange(Nws) return ws[np.argmin([mse(x, deconv_wiener(y, h, w)) for w in ws])]
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)
h = psf(x.shape,(5.,5.)) h2 = psf(x.shape,(11,3)) y = myconvolve(x,h)+s*np.amax(x)*np.random.uniform(0,1,x.shape) y2 = myconvolve(x,h2)+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,10.,1.) u2 = deconv_wiener(y,h,0.1) #3d from spimagine import read3dTiff x = read3dTiff("data/usaf3d.tif")[100:228,100:228,100:228] h = psf(x.shape,(3.,3.,11)) h2 = psf(x.shape,(11,3,3)) h3 = psf(x.shape,(3,11,3)) y = myconvolve(x,h)+.1*np.amax(x)*np.random.uniform(0,1,x.shape) y2 = myconvolve(x,h2)+.1*np.amax(x)*np.random.uniform(0,1,x.shape) y3 = myconvolve(x,h3)+.1*np.amax(x)*np.random.uniform(0,1,x.shape) u = deconv_tv_al([y,y2,y3],[h,h2,h3],100.,1.)
def err(gamma): u = deconv_wiener(y, h, gamma=gamma) u *= np.mean(y) / np.mean(u) return rms(d0, u)
def gmin_for_sig(sig_level=0.1, maxiter=20): d0, y, noise, h = form_image(sig_level) g = get_gamma_min(d0, y, h, maxiter=maxiter) u = deconv_wiener(y, h, g) return d0, y, h, u, g
np.random.seed(0) # 2d from matplotlib.pyplot import imread x = imread("data/usaf.png") x = np.pad(x, ((256,) * 2,) * 2, mode="constant") h = psf(x.shape, (3.0, 11)) h2 = psf(x.shape, (11, 3)) y = myconvolve(x, h) + 0.3 * np.amax(x) * np.random.uniform(0, 1, x.shape) y2 = myconvolve(x, h2) + 0.3 * np.amax(x) * np.random.uniform(0, 1, x.shape) u1 = deconv_wiener([y, y2], [h, h2], 1.0e-6) u2 = deconv_wiener2([y, y2], [h2, h], 1.0e-6) # #3d # from spimagine import read3dTiff # # x = read3dTiff("data/usaf3d.tif")[100:228,100:228,100:228] # h = psf(x.shape,(3.,3.,11)) # # h2 = psf(x.shape,(11,3,3)) # h3 = psf(x.shape,(3,11,3)) # # y = myconvolve(x,h)+.1*np.amax(x)*np.random.uniform(0,1,x.shape) # y2 = myconvolve(x,h2)+.1*np.amax(x)*np.random.uniform(0,1,x.shape) # y3 = myconvolve(x,h3)+.1*np.amax(x)*np.random.uniform(0,1,x.shape)