def solve(self): for i in range(total_ite): roopcount = roopcount + 1 X, y, prx, dux, hize = coefficient_learning( d, X, y, S, N * N, M, rhox, lamd, d_size, coef_ite) # logging prx_log.append(prx[coef_ite - 1]) dux_log.append(dux[coef_ite - 1]) hizero.append(hize) # fft xf = X_to_xf(X, N * N, M) d, dcon, prd, dud = dictinary_learning(d, dcon, xf, S, N * N, M, rhod, d_size, dict_ite) # logging prd_log.append(prd[0]) dud_log.append(dud[0]) # prox of support function d = pr_d(d, N * N, M, d_size) # X = X.transpose(1, 2, 0) # crop d = d[:, :d_size, :d_size] if i == total_ite - 1: d = d.transpose(1, 2, 0) plot.imview(util.tiledict(d), fgsz=(7, 7)) d = d.transpose(2, 0, 1) mindx_s = dx_s(d, xf, S, N * N, M, K, d_size) + lamd * l1x(X, N * N, M) goal.append(mindx_s) D = D_to_d(d, N * N, d_size) image = reconstruct(xf[0], D, N * N, M) print("iterate number: ", roopcount) imgr = sl1 + image # imgr = image print("Reconstruction PSNR: %.2fdB\n" % sm.psnr(ori[0], imgr))
def testdict(cri, Dr0, Dr, Slr, Shr, dir, lambdas = [ '1e-2', '2e-2', '5e-2', '1e-1', '2e-1', '5e-1', ]): S = (Slr + Shr).squeeze() ret = [[] for k in range(cri.K)] for s in lambdas: print('==========================================') print('test dictionary (lambda = %s)' % s) print('==========================================') lmbda = float(s) Xr = calcXr(cri, Dr, Shr, lmbda=lmbda) X = Xr.squeeze() S_ = (reconstruct(cri, Dr, Xr) + Slr).squeeze() for k in range(cri.K): d = { 'lambda': lmbda, 'psnr': sm.psnr(S.T[k].T, S_.T[k].T), 'ssim': compare_ssim(S.T[k].T, S_.T[k].T), 'l0norm': strict_l0norm(np.rollaxis(X, 2)[k]), } pprint.pprint(d) ret[k].append(d) save_result(Dr0.squeeze(), Dr.squeeze(), X, (Slr + Shr).squeeze(), S_, dir + '/result_lambda=%s.png' % s) return ret
def test_03(self): N = 16 x = np.random.randn(N) x -= x.min() x /= x.max() y = x + 1 assert np.abs(metric.psnr(x, y)) < 1e-8
def run_cbpdn(D, sl, sh, lmbda, test_blob=None, opt=None): """Run ConvBPDN solver and compute statistics.""" opt = cbpdn.ConvBPDN.Options(opt) if test_blob is None: test_blob = sl + sh solver = cbpdn.ConvBPDN(D, sh, lmbda, opt=opt) solver.solve() fnc = solver.getitstat().ObjFun[-1] shr = solver.reconstruct().reshape(sl.shape) imgr = sl + shr psnr = 0. for idx in range(sh.shape[-1]): psnr += sm.psnr(test_blob[..., idx], imgr[..., idx], rng=1.) psnr /= test_blob.shape[-1] if _cfg.VERBOSE: print('.', end='', flush=True) return fnc, psnr
def save_result(D0, D, X, S, S_reconstructed, filename): titles = [[], []] r1 = [] for k in range(S.shape[-1]): r1.append(S.T[k].T) titles[0].append('') r1.append(util.tiledict(D0)) titles[0].append('') r2 = [] for k in range(S.shape[-1]): r2.append(S_reconstructed.T[k].T) psnr = sm.psnr(S.T[k].T, S_reconstructed.T[k].T) ssim = compare_ssim(S.T[k].T, S_reconstructed.T[k].T) l0 = strict_l0norm(np.rollaxis(X, 2)[k]) titles[1].append("PSNR: %.3fdb\nSSIM: %.4f\nl0norm: %d" % (psnr, ssim, l0)) r2.append(util.tiledict(D)) titles[1].append('') saveimg2D(np.array([r1, r2]), filename, np.array(titles))
def run_cbpdn_gpu(D, sl, sh, lmbda, test_blob=None, opt=None): """Run GPU version of CBPDN. Only supports grayscale images.""" assert _cfg.TEST.DATASET.GRAY, 'Only grayscale images are supported' assert cucbpdn is not None, 'GPU CBPDN is not supported' opt = cbpdn.ConvBPDN.Options(opt) if test_blob is None: test_blob = sl + sh fnc, psnr = 0., 0. for idx in range(test_blob.shape[-1]): X = cucbpdn.cbpdn(D, sh[..., idx].squeeze(), lmbda, opt=opt) shr = np.sum(spl.fftconv(D, X), axis=2) dfd = linalg.norm(shr.ravel() - sh[..., idx].ravel()) rl1 = linalg.norm(X.ravel(), 1) obj = dfd + lmbda * rl1 fnc += obj imgr = sl[..., idx] + shr psnr += sm.psnr(imgr, test_blob[..., idx].squeeze(), rng=1.) psnr /= test_blob.shape[-1] if _cfg.VERBOSE: print('.', end='', flush=True) return fnc, psnr
print('Running on GPU %d (%s)\n' % (id, info[id].name)) b = pdcsc.ConvProdDictBPDN(np2cp(D), np2cp(B), np2cp(shc), lmbda, opt, dimK=0) X = cp2np(b.solve()) print("ConvProdDictBPDN solve time: %.2fs" % b.timer.elapsed('solve')) """ Compute partial and full reconstructions from sparse representation $X$ with respect to convolutional dictionary $D$ and standard dictionary $B$. The partial reconstructions are $DX$ and $XB$, and the full reconstruction is $DXB$. """ DX = fft.fftconv(D[..., np.newaxis, np.newaxis, :], X, axes=(0, 1)) XB = linalg.dot(B, X, axis=2) shr = cp2np(b.reconstruct().squeeze()) imgr = slc + shr print("Reconstruction PSNR: %.2fdB\n" % metric.psnr(img, imgr)) """ Display original and reconstructed images. """ gamma = lambda x, g: np.sign(x) * (np.abs(x)**g) fig, ax = plot.subplots(nrows=2, ncols=2, figsize=(14, 14)) plot.imview(img, title='Original image', ax=ax[0, 0], fig=fig) plot.imview(slc, title='Lowpass component', ax=ax[0, 1], fig=fig) plot.imview(imgr, title='Reconstructed image', ax=ax[1, 0], fig=fig) plot.imview(gamma(shr, 0.6), title='Reconstructed highpass component', ax=ax[1, 1], fig=fig) fig.show()
""" The denoised estimate of the image is just the reconstruction from all coefficient maps. """ imgdp = cp2np(b.reconstruct().squeeze()) imgd = crop(imgdp) """ Display solve time and denoising performance. """ print("ConvProdDictL1L1Grd solve time: %5.2f s" % b.timer.elapsed('solve')) print("Noisy image PSNR: %5.2f dB" % sm.psnr(img, imgn)) print("Denoised image PSNR: %5.2f dB" % sm.psnr(img, imgd)) """ Display the reference, noisy, and denoised images. """ fig, ax = plot.subplots(nrows=1, ncols=3, figsize=(21, 7)) fig.suptitle('ConvProdDictL1L1GrdJoint Results (false colour, ' 'bands 10, 20, 30)') plot.imview(img[..., 10:40:10], title='Reference', ax=ax[0], fig=fig) plot.imview(imgn[..., 10:40:10], title='Noisy', ax=ax[1], fig=fig) plot.imview(imgd[..., 10:40:10], title='Denoised', ax=ax[2], fig=fig) fig.show()
ams = cbpdn.AddMaskSim(cbpdn.ConvBPDNGradReg, Di, imgwp, mskp, lmbda, mu, opt=opt) X = ams.solve().squeeze() t = ams.timer.elapsed('solve') imgr = crop(ams.reconstruct().squeeze()) """ Display solve time and reconstruction performance. """ print("AddMaskSim wrapped ConvBPDN solve time: %.2fs" % t) print("Corrupted image PSNR: %5.2f dB" % metric.psnr(img, imgw)) print("Recovered image PSNR: %5.2f dB" % metric.psnr(img, imgr)) """ Display reference, test, and reconstructed image """ fig = plot.figure(figsize=(21, 7)) plot.subplot(1, 3, 1) plot.imview(img, title='Reference image', fig=fig) plot.subplot(1, 3, 2) plot.imview(imgw, title='Corrupted image', fig=fig) plot.subplot(1, 3, 3) plot.imview(imgr, title='Reconstructed image', fig=fig) fig.show() """ Display lowpass component and sparse representation
def test_04(self): N = 16 x = np.random.randn(N) y = x + 1 assert np.abs(metric.psnr(x, y, rng=1.0)) < 1e-8
""" Initialise and run CSC solver. """ b = cbpdn.ConvBPDNProjL1(D, sh, gamma, opt) X = b.solve() print("ConvBPDNProjL1 solve time: %.2fs" % b.timer.elapsed('solve')) """ Reconstruct image from sparse representation. """ shr = b.reconstruct().squeeze() imgr = sl + shr print("Reconstruction PSNR: %.2fdB\n" % sm.psnr(img, imgr)) """ Display low pass component and sum of absolute values of coefficient maps of highpass component. """ fig = plot.figure(figsize=(14, 7)) plot.subplot(1, 2, 1) plot.imview(sl, title='Lowpass component', fig=fig) plot.subplot(1, 2, 2) plot.imview(np.sum(abs(X), axis=b.cri.axisM).squeeze(), cmap=plot.cm.Blues, title='Sparse representation', fig=fig) fig.show()
'MaxMainIter': 12, 'rho': 1.8e-1, 'Y0': imgb }) """ Create solver object and solve, returning the the demosaiced image ``imgp``. """ b = PPP(img.shape, f, proxf, proxg, opt=opt) imgp = b.solve() """ Display solve time and demosaicing performance. """ print("PPP ADMM solve time: %5.2f s" % b.timer.elapsed('solve')) print("Baseline demosaicing PSNR: %5.2f dB" % metric.psnr(img, imgb)) print("PPP demosaicing PSNR: %5.2f dB" % metric.psnr(img, imgp)) """ Display reference and demosaiced images. """ fig, ax = plot.subplots(nrows=1, ncols=3, sharex=True, sharey=True, figsize=(21, 7)) plot.imview(img, title='Reference', fig=fig, ax=ax[0]) plot.imview(imgb, title='Baseline demoisac: %.2f (dB)' % metric.psnr(img, imgb), fig=fig, ax=ax[1])
imgd = crop(imgdp) """ Keep a copy of the low-frequency component estimate from this solution for use in the next approach. """ imglp = X[..., 0, 3:6].squeeze() """ Display solve time and denoising performance. """ print("ConvBPDNGradReg solve time: %5.2f s" % b.timer.elapsed('solve')) print("Noisy image PSNR: %5.2f dB" % sm.psnr(img, imgn)) print("Denoised image PSNR: %5.2f dB" % sm.psnr(img, imgd)) """ Display the reference, noisy, and denoised images. """ fig, ax = plot.subplots(nrows=1, ncols=3, figsize=(21, 7)) fig.suptitle('Method 1 Results') plot.imview(img, ax=ax[0], title='Reference', fig=fig) plot.imview(imgn, ax=ax[1], title='Noisy', fig=fig) plot.imview(imgd, ax=ax[2], title='CSC Result', fig=fig) fig.show()
def psnr(*args, **kwargs): warnings.warn("sporco.linalg.psnr is deprecated: use sporco.metric.psnr", PendingDeprecationWarning) return sm.psnr(*args, **kwargs)
""" Reconstruct from representation. """ imgr = crop(sl + ams.reconstruct().squeeze()) """ Display solve time and reconstruction performance. """ print("AddMaskSim wrapped ConvBPDN solve time: %.2fs" % ams.timer.elapsed('solve')) print("Corrupted image PSNR: %5.2f dB" % metric.psnr(img, imgw)) print("Recovered image PSNR: %5.2f dB" % metric.psnr(img, imgr)) """ Display reference, test, and reconstructed image """ fig = plot.figure(figsize=(21, 7)) plot.subplot(1, 3, 1) plot.imview(img, title='Reference image', fig=fig) plot.subplot(1, 3, 2) plot.imview(imgw, title='Corrupted image', fig=fig) plot.subplot(1, 3, 3) plot.imview(imgr, title='Reconstructed image', fig=fig) fig.show()
X = cp2np(X) print("ConvBPDN solve time: %.2fs" % b.timer.elapsed('solve')) """ Reconstruct image from sparse representation. """ recon = b.reconstruct().squeeze() if CUPY: audio = cp2np(audio) recon = cp2np(recon) print("Reconstruction PSNR: %.2fdB\n" % sm.psnr(audio, recon)) """ Show activation map across time. You may have to zoom in to see well-localized activations. """ wl, hl = 160, 80 # Get activation magnitude and apply padding in preparation for frame conversion X = X.squeeze().T # Keep track of the original length len_orig = X.shape[-1] # Number of frames available num_frms = (len_orig - 1) // hl + 1 # Pad the number of activations to end on a full frame
d = pr_d(d, N * N, M, d_size) # X = X.transpose(1, 2, 0) # crop d = d[:, :d_size, :d_size] if i == total_ite - 1: d = d.transpose(1, 2, 0) plot.imview(util.tiledict(d), fgsz=(7, 7)) d = d.transpose(2, 0, 1) mindx_s = dx_s(d, xf, S, N * N, M, K, d_size) + lamd * l1x(X, N * N, M) goal.append(mindx_s) D = D_to_d(d, N * N, d_size) image = reconstruct(xf[0], D, N * N, M) print("iterate number: ", roopcount) imgr = sl1 + image # imgr = image print("Reconstruction PSNR: %.2fdB\n" % sm.psnr(ori[0], imgr)) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # L2 - L1 DR # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # for i in range(total_ite): # roopcount = roopcount + 1 # X, y, prx, dux, hize = coefficient_learning_l2( # d, X, y, S, N * N, M, rhox, lamd, d_size, coef_ite) # prx_log.append(prx[coef_ite - 1]) # dux_log.append(dux[coef_ite - 1]) # hizero.append(hize) # xf = X_to_xf(X, N * N, M) # d, dcon, prd, dud = dictinary_learning_l2( # d, dcon, xf, S, N * N, M, rhod, d_size, dict_ite) # prd_log.append(prd[0])
return np.pad(x, ((n, n), (n, n), (0, 0)), mode='symmetric') def crop(x, n=8): return x[n:-n, n:-n] # img = util.ExampleImages().image('monarch.png', zoom=0.5, scaled=True, # gray=True, idxexp=np.s_[:, 160:672]) img = mpimg.imread('barbara1.png') np.random.seed(12345) imgn = img + np.random.normal(0.0, 0.1, img.shape) print("Noisy image PSNR: %5.2f dB" % sm.psnr(img, imgn)) npd = 16 fltlmbd = 5.0 imgnl, imgnh = util.tikhonov_filter(imgn, fltlmbd, npd) D = util.convdicts()['G:8x8x32'] D = D[:, :, 0:14] # D = np.random.randn(8, 8, 14) imgnpl, imgnph = util.tikhonov_filter(pad(imgn), fltlmbd, npd) W = spl.irfftn( np.conj(spl.rfftn(D, imgnph.shape, (0, 1))) * spl.rfftn(imgnph[..., np.newaxis], None, (0, 1)), imgnph.shape, (0, 1)) W = W**2 W = 1.0 / (np.maximum(np.abs(W), 1e-8)) lmbda = 1.5e-2
def psnr(*args, **kwargs): warnings.warn("sporco.linalg.psnr is deprecated: please use"\ " sporco.metric.psnr") return sm.psnr(*args, **kwargs)
""" The denoised estimate of the image is by aggregating the block reconstructions from the coefficient maps. """ imgd_mean = util.average_blocks(np.dot(D, X).reshape(blksz + (-1,)) + blockmeans, img.shape, stpsz) imgd_median = util.combine_blocks(np.dot(D, X).reshape(blksz + (-1,)) + blockmeans, img.shape, stpsz, np.median) """ Display solve time and denoising performance. """ print("BPDN solve time: %5.2f s" % b.timer.elapsed('solve')) print("Noisy image PSNR: %5.2f dB" % sm.psnr(img, imgn)) print("Denoised mean image PSNR: %5.2f dB" % sm.psnr(img, imgd_mean)) print("Denoised median image PSNR: %5.2f dB" % sm.psnr(img, imgd_median)) """ Display the reference, noisy, and denoised images. """ fig = plot.figure(figsize=(14, 14)) plot.subplot(2, 2, 1) plot.imview(img, title='Reference', fig=fig) plot.subplot(2, 2, 2) plot.imview(imgn, title='Noisy', fig=fig) plot.subplot(2, 2, 3) plot.imview(imgd_mean, title='SC mean Result', fig=fig)
""" The denoised estimate of the image is by aggregating the block reconstructions from the coefficient maps. """ imgd_mean = util.averageblocks(np.dot(D, X).reshape(blksz + (-1,)) + blockmeans, img.shape, stpsz) imgd_median = util.combineblocks(np.dot(D, X).reshape(blksz + (-1,)) + blockmeans, img.shape, stpsz, np.median) """ Display solve time and denoising performance. """ print("BPDN solve time: %5.2f s" % b.timer.elapsed('solve')) print("Noisy image PSNR: %5.2f dB" % sm.psnr(img, imgn)) print("Denoised mean image PSNR: %5.2f dB" % sm.psnr(img, imgd_mean)) print("Denoised median image PSNR: %5.2f dB" % sm.psnr(img, imgd_median)) """ Display the reference, noisy, and denoised images. """ fig = plot.figure(figsize=(14, 14)) plot.subplot(2, 2, 1) plot.imview(img, title='Reference', fig=fig) plot.subplot(2, 2, 2) plot.imview(imgn, title='Noisy', fig=fig) plot.subplot(2, 2, 3) plot.imview(imgd_mean, title='SC mean Result', fig=fig)
""" Create solver object and solve, returning the the denoised image ``imgr``. """ b = tvl2.TVL2Deconv(np.ones((1,1)), imgn, lmbda, opt) imgr = b.solve() """ Display solve time and denoising performance. """ print("TVL2Deconv solve time: %5.2f s" % b.timer.elapsed('solve')) print("Noisy image PSNR: %5.2f dB" % metric.psnr(img, imgn)) print("Denoised image PSNR: %5.2f dB" % metric.psnr(img, imgr)) """ Display reference, corrupted, and denoised images. """ fig = plot.figure(figsize=(20, 5)) plot.subplot(1, 3, 1) plot.imview(img, title='Reference', fig=fig) plot.subplot(1, 3, 2) plot.imview(imgn, title='Corrupted', fig=fig) plot.subplot(1, 3, 3) plot.imview(imgr, title=r'Restored ($\ell_2$-TV)', fig=fig) fig.show()
(b.timer.elapsed('solve_wo_rsdl')/b_par.timer.elapsed('solve_wo_rsdl'))) """ Reconstruct images from sparse representations. """ imgr = crop(sl + b.reconstruct().squeeze()) imgr_par = crop(sl + b_par.reconstruct().squeeze()) """ Report performances of different methods of solving the same problem. """ print("Corrupted image PSNR: %5.2f dB" % metric.psnr(img, imgw)) print("Serial Reconstruction PSNR: %5.2f dB" % metric.psnr(img, imgr)) print("Parallel Reconstruction PSNR: %5.2f dB\n" % metric.psnr(img, imgr_par)) """ Display reference, test, and reconstructed images """ fig = plot.figure(figsize=(14, 14)) plot.subplot(2, 2, 1) plot.imview(img, fig=fig, title='Reference Image') plot.subplot(2, 2, 2) plot.imview(imgw, fig=fig, title=('Corrupted Image PSNR: %5.2f dB' % metric.psnr(img, imgw))) plot.subplot(2, 2, 3)
# Set up ConvBPDNMaskDcpl options lmbda = 1e-3 opt = cbpdn.ConvBPDNMaskDcpl.Options({'Verbose' : True, 'MaxMainIter' : 500, 'HighMemSolve' : False, 'RelStopTol' : 1e-3, 'AuxVarObj' : False, 'RelaxParam' : 1.0, 'rho' : 2e-1, 'LinSolveCheck' : True, 'AutoRho' : {'Enabled' : False, 'StdResiduals' : True}}) # Initialise and run ConvBPDNMaskDcpl object b = cbpdn.ConvBPDNMaskDcpl(D, S, lmbda, W, opt) X = b.solve() print("ConvBPDNMaskDcpl solve time: %.2fs" % b.runtime) # Reconstruct representation Sr = b.reconstruct().squeeze() print(" reconstruction PSNR: %.2fdB\n" % sm.psnr(S, Sr)) # Display representation and reconstructed image fig1 = plot.figure(1, figsize=(14,14)) plot.subplot(2,2,1) plot.imview(np.squeeze(np.sum(abs(X), axis=b.cri.axisM)), fgrf=fig1, cmap=plot.cm.Blues, title='Representation') plot.subplot(2,2,2) plot.imview(S, fgrf=fig1, cmap=plot.cm.Blues, title='Reference image') plot.subplot(2,2,3) plot.imview(Sr, fgrf=fig1, cmap=plot.cm.Blues, title='Reconstructed image') plot.subplot(2,2,4) plot.imview(W[...,np.newaxis] * Sr, fgrf=fig1, title='Masked reconstructed image') fig1.show()
""" Reconstruct images from sparse representations. """ shr = b.reconstruct().squeeze() imgr = sl + shr shr_par = b_par.reconstruct().squeeze() imgr_par = sl + shr_par """ Report performances of different methods of solving the same problem. """ print("Serial reconstruction PSNR: %.2fdB" % sm.psnr(img, imgr)) print("Parallel reconstruction PSNR: %.2fdB\n" % sm.psnr(img, imgr_par)) """ Display original and reconstructed images. """ fig = plot.figure(figsize=(21, 7)) plot.subplot(1, 3, 1) plot.imview(img, title='Original', fig=fig) plot.subplot(1, 3, 2) plot.imview(imgr, title=('Serial Reconstruction PSNR: %5.2f dB' % sm.psnr(img, imgr)), fig=fig) plot.subplot(1, 3, 3) plot.imview(imgr_par, title=('Parallel Reconstruction PSNR: %5.2f dB' %
} }) """ Initialise and run CSC solver. """ b = cbpdn.ConvMinL1InL2Ball(D, sh, epsilon, opt) X = b.solve() print("ConvMinL1InL2Ball solve time: %.2fs" % b.timer.elapsed('solve')) """ Reconstruct image from sparse representation. """ shr = b.reconstruct().squeeze() imgr = sl + shr print("Reconstruction PSNR: %.2fdB\n" % sm.psnr(img, imgr)) """ Display low pass component and sum of absolute values of coefficient maps of highpass component. """ fig = plot.figure(figsize=(14, 7)) plot.subplot(1, 2, 1) plot.imview(sl, title='Lowpass component', fig=fig) plot.subplot(1, 2, 2) plot.imview(np.sum(abs(X), axis=b.cri.axisM).squeeze(), cmap=plot.cm.Blues, title='Sparse representation', fig=fig) fig.show() """ Display original and reconstructed images.
"ParConvBPDN was %.2f times faster than ConvBPDN\n" % (b.timer.elapsed('solve_wo_rsdl') / b_par.timer.elapsed('solve_wo_rsdl'))) """ Reconstruct images from sparse representations. """ shr = b.reconstruct().squeeze() imgr = sl + shr shr_par = b_par.reconstruct().squeeze() imgr_par = sl + shr_par """ Report performances of different methods of solving the same problem. """ print("Serial reconstruction PSNR: %.2fdB" % sm.psnr(img, imgr)) print("Parallel reconstruction PSNR: %.2fdB\n" % sm.psnr(img, imgr_par)) """ Display original and reconstructed images. """ fig = plot.figure(figsize=(21, 7)) plot.subplot(1, 3, 1) plot.imview(img, title='Original', fig=fig) plot.subplot(1, 3, 2) plot.imview(imgr, title=('Serial Reconstruction PSNR: %5.2f dB' % sm.psnr(img, imgr)), fig=fig) plot.subplot(1, 3, 3) plot.imview(imgr_par,
'AutoRho': { 'Enabled': True } }) """ Create solver object and solve, returning the the denoised image ``imgr``. """ b = tvl2.TVL2Denoise(imgn, lmbda, opt) imgr = b.solve() """ Display solve time and denoising performance. """ print("TVL2Denoise solve time: %5.2f s" % b.timer.elapsed('solve')) print("Noisy image PSNR: %5.2f dB" % metric.psnr(img, imgn)) print("Denoised image PSNR: %5.2f dB" % metric.psnr(img, imgr)) """ Display reference, corrupted, and denoised images. """ fig = plot.figure(figsize=(20, 5)) plot.subplot(1, 3, 1) plot.imview(img, fgrf=fig, title='Reference') plot.subplot(1, 3, 2) plot.imview(imgn, fgrf=fig, title='Corrupted') plot.subplot(1, 3, 3) plot.imview(imgr, fgrf=fig, title=r'Restored ($\ell_2$-TV)') fig.show() """ Get iterations statistics from solver object and plot functional value, ADMM primary and dual residuals, and automatically adjusted ADMM penalty parameter against the iteration number.
""" Create solver object and solve, returning the the demosaiced image ``imgp``. """ b = PPP(img.shape, f, gradf, proxg, opt=opt) imgp = b.solve() """ Display solve time and demosaicing performance. """ print("PPP PGM solve time: %5.2f s" % b.timer.elapsed('solve')) print("Baseline demosaicing PSNR: %5.2f dB" % metric.psnr(img, imgb)) print("PPP demosaicing PSNR: %5.2f dB" % metric.psnr(img, imgp)) """ Display reference and demosaiced images. """ fig, ax = plot.subplots(nrows=1, ncols=3, sharex=True, sharey=True, figsize=(21, 7)) plot.imview(img, title='Reference', fig=fig, ax=ax[0]) plot.imview(imgb, title='Baseline demoisac: %.2f (dB)' % metric.psnr(img, imgb), fig=fig, ax=ax[1]) plot.imview(imgp, title='PPP demoisac: %.2f (dB)' % metric.psnr(img, imgp), fig=fig, ax=ax[2]) fig.show()