d.display_start() for it in range(iter): img_index = np.random.randint(0, sh.shape[-1]) d.solve(sh[..., [img_index]]) d.display_end() D1 = d.getdict() print("OnlineConvBPDNDictLearn solve time: %.2fs" % d.timer.elapsed('solve')) """ Display initial and final dictionaries. """ D1 = D1.squeeze() fig = plot.figure(figsize=(14, 7)) plot.subplot(1, 2, 1) plot.imview(util.tiledict(D0), title='D0', fig=fig) plot.subplot(1, 2, 2) plot.imview(util.tiledict(D1), title='D1', fig=fig) fig.show() """ Get iterations statistics from solver object and plot functional value. """ its = d.getitstat() fig = plot.figure(figsize=(7, 7)) plot.plot(np.vstack((its.DeltaD, its.Eta)).T, xlbl='Iterations', lgnd=('Delta D', 'Eta'), fig=fig)
""" Plot comparison of reference and recovered representations. """ plot.plot(np.hstack((x0, x)), title='Sparse representation', lgnd=['Reference', 'Reconstructed']) """ Plot lmbda error curve, functional value, residuals, and rho """ its = b.getitstat() fig = plot.figure(figsize=(15, 10)) plot.subplot(2, 2, 1) plot.plot(fvmx, x=lrng, ptyp='semilogx', xlbl='$\lambda$', ylbl='Error', fig=fig) plot.subplot(2, 2, 2) plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig) plot.subplot(2, 2, 3) plot.plot(np.vstack((its.PrimalRsdl, its.DualRsdl)).T, ptyp='semilogy', xlbl='Iterations', ylbl='Residual', lgnd=['Primal', 'Dual'], fig=fig) plot.subplot(2, 2, 4) plot.plot(its.Rho, xlbl='Iterations', ylbl='Penalty Parameter', fig=fig) fig.show()
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() """ 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. """ its = b.getitstat() fig = plot.figure(figsize=(20, 5)) plot.subplot(1, 3, 1) plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig) plot.subplot(1, 3, 2) plot.plot(np.vstack((its.PrimalRsdl, its.DualRsdl)).T, ptyp='semilogy', xlbl='Iterations', ylbl='Residual', lgnd=['Primal', 'Dual'], fig=fig) plot.subplot(1, 3, 3) plot.plot(its.Rho, xlbl='Iterations', ylbl='Penalty Parameter', fig=fig) fig.show() # Wait for enter on keyboard input()
""" 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. """ fig = plot.figure(figsize=(14, 7)) plot.subplot(1, 2, 1) plot.imview(img, title='Original', fig=fig)
print('Solve time: %.2f s' % t) """ Reconstruct the image from the sparse representation. """ imgr = np.sum(spl.fftconv(D, X), axis=2) print("Reconstruction PSNR: %.2fdB\n" % spm.psnr(img, imgr)) """ Display representation and reconstructed image. """ fig = plot.figure(figsize=(14, 14)) plot.subplot(2, 2, 1) plot.imview(X[..., 0].squeeze(), title='Lowpass component', fig=fig) plot.subplot(2, 2, 2) plot.imview(np.sum(abs(X[..., 1:]), axis=2).squeeze(), cmap=plot.cm.Blues, title='Main representation', fig=fig) plot.subplot(2, 2, 3) plot.imview(imgr, title='Reconstructed image', fig=fig) plot.subplot(2, 2, 4) plot.imview(imgr - img, fltscl=True, title='Reconstruction difference', fig=fig) fig.show() # Wait for enter on keyboard input()
""" Display solve time and denoising performance. """ print("ConvBPDN 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 = plot.figure(figsize=(21, 7)) plot.subplot(1, 3, 1) plot.imview(img, title='Reference', fig=fig) plot.subplot(1, 3, 2) plot.imview(imgn, title='Noisy', fig=fig) plot.subplot(1, 3, 3) plot.imview(imgd, title='CSC Result', fig=fig) fig.show() """ Plot functional evolution during ADMM iterations. """ its = b.getitstat() plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional')
""" 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) plot.imview(imgr, fig=fig, title=('Serial reconstruction PSNR: %5.2f dB' % metric.psnr(img, imgr))) plot.subplot(2, 2, 4) plot.imview(imgr_par, fig=fig, title=('Parallel reconstruction PSNR: %5.2f dB' % metric.psnr(img, imgr_par))) fig.show() """
""" Plot the three functions on the same axes. """ plot.plot(np.stack((y1, y2, y3)).T, x, xlbl='x', ylbl='y', title='Plot Example', lgnd=('$|x|$', '$|x|^{(3/2)}$', '$x^2$'), lglc='upper center') """ We can also create a plot and then add to it. In this case we need to create the figure object separately and pass it as argument to the :func:`.plot.plot` function so that it doesn't automatically call `fig.show` after the first plot call. """ fig = plot.figure() plot.plot(np.stack((y1, y2, y3)).T, x, xlbl='x', ylbl='y', title='Plot Example', lgnd=('$|x|$', '$|x|^{(3/2)}$', '$x^2$'), lglc='upper center', fig=fig) plot.plot(y1[::5], x[::5], lw=0, ms=8.0, marker='o', fig=fig) fig.show() """ Define `x` and `y` arrays and a 2-d surface on `x`, `y`. """ x = np.linspace(0, 2, 50)[np.newaxis, :] y = np.linspace(-1, 1, 51)[:, np.newaxis] z = np.sin(y) * np.cos(2*x*y)
print("BPDN standard FISTA backtracking solve time: %.2fs" % b.timer.elapsed('solve')) print("") """ Plot comparison of reference and recovered representations. """ plot.plot(np.hstack((x0, x)), title='Sparse representation (standard FISTA)', lgnd=['Reference', 'Reconstructed']) """ Plot lmbda error curve, functional value, residuals, and rho """ its = b.getitstat() fig = plot.figure(figsize=(21, 7)) plot.subplot(1, 3, 1) plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig) plot.subplot(1, 3, 2) plot.plot(its.Rsdl, ptyp='semilogy', xlbl='Iterations', ylbl='Residual', fig=fig) plot.subplot(1, 3, 3) plot.plot(its.L, xlbl='Iterations', ylbl='Inverse of Step Size (Standard FISTA)', fig=fig) fig.show() """
""" Display solve time and denoising performance. """ print("TVL1Denoise 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_1$-TV)', fig=fig) 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. """ its = b.getitstat() fig = plot.figure(figsize=(20, 5))
# Initialise and run ConvBPDN object b = cbpdn.ConvBPDN(D, sh, lmbda, opt) X = b.solve() print("ConvBPDN solve time: %.2fs" % b.timer.elapsed('solve')) # Reconstruct representation shr = b.reconstruct().squeeze() imgr = sl + shr print("reconstruction PSNR: %.2fdB\n" % sm.psnr(img, imgr)) # Display representation and reconstructed image fig1 = plot.figure(1, figsize=(14,14)) plot.subplot(2,2,1) plot.imview(sl, fgrf=fig1, title='Lowpass component') plot.subplot(2,2,2) plot.imview(np.sum(abs(X), axis=b.cri.axisM).squeeze(), fgrf=fig1, cmap=plot.cm.Blues, title='Main representation') plot.subplot(2,2,3) plot.imview(imgr, fgrf=fig1, title='Reconstructed image') plot.subplot(2,2,4) plot.imview(imgr - img, fgrf=fig1, fltscl=True, title='Reconstruction difference') fig1.show() # Plot functional value, residuals, and rho its = b.getitstat()
c = cbpdn.ConvBPDN(D, sh, lmbda, opt) X = c.solve().squeeze() t = c.timer.elapsed('solve') print('Solve time: %.2f s' % t) """ Reconstruct the image from the sparse representation. """ shr = np.sum(spl.fftconv(D, X), axis=2) imgr = sl + shr print("Reconstruction PSNR: %.2fdB\n" % spm.psnr(img, imgr)) """ Display representation and reconstructed image. """ fig = plot.figure(figsize=(14, 14)) plot.subplot(2, 2, 1) plot.imview(sl, fgrf=fig, title='Lowpass component') plot.subplot(2, 2, 2) plot.imview(np.sum(abs(X), axis=2).squeeze(), fgrf=fig, cmap=plot.cm.Blues, title='Main representation') plot.subplot(2, 2, 3) plot.imview(imgr, fgrf=fig, title='Reconstructed image') plot.subplot(2, 2, 4) plot.imview(imgr - img, fgrf=fig, fltscl=True, title='Reconstruction difference') fig.show()
def test_02(self): x = np.linspace(-1, 1, 20) y = x**2 fig = plot.figure() plot.plot(y, x=x, title='Plot Test', xlbl='x', ylbl='y', fgrf=fig) plot.close()
} }) """ Create solver object and solve. """ d = parcnsdl.ConvBPDNDictLearn_Consensus(D0, sh, lmbda, opt) D1 = d.solve() print("ConvBPDNDictLearn_Consensus solve time: %.2fs" % d.timer.elapsed('solve')) """ Display initial and final dictionaries. """ D1 = D1.squeeze() fig = plot.figure(figsize=(14, 7)) plot.subplot(1, 2, 1) plot.imview(util.tiledict(D0), title='D0', fig=fig) plot.subplot(1, 2, 2) plot.imview(util.tiledict(D1), title='D1', fig=fig) fig.show() """ Get iterations statistics from solver object and plot functional value """ its = d.getitstat() plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional') # Wait for enter on keyboard input()
""" Plot comparison of reference and recovered representations. """ plot.plot(np.hstack((x0, x)), title='Sparse representation', lgnd=['Reference', 'Reconstructed']) """ Plot lmbda error curve, functional value, residuals, and rho """ its = b.getitstat() fig = plot.figure(figsize=(15, 10)) plot.subplot(2, 2, 1) plot.plot(fvmx, x=lrng, ptyp='semilogx', xlbl='$\lambda$', ylbl='Error', fgrf=fig) plot.subplot(2, 2, 2) plot.plot(its.ObjFun, fgrf=fig, xlbl='Iterations', ylbl='Functional') plot.subplot(2, 2, 3) plot.plot(np.vstack((its.PrimalRsdl, its.DualRsdl)).T, fgrf=fig, ptyp='semilogy', xlbl='Iterations', ylbl='Residual', lgnd=['Primal', 'Dual']) plot.subplot(2, 2, 4) plot.plot(its.Rho, fgrf=fig, xlbl='Iterations', ylbl='Penalty Parameter') fig.show()