CSC with a Spatial Mask

This example demonstrates the use of cbpdn.AddMaskSim for convolutional sparse coding with a spatial mask [34]. If the sporco-cuda extension is installed and a GPU is available, a GPU accelerated version is used. The example problem is inpainting of randomly distributed corruption of a greyscale image. This is the same problem solved by example cbpdn_ams_gry, but with a different approach to handling of the lowpass image components. In this example, instead of pre-processing with a non-linear lowpass filter, the lowpass components are represented within the main optimisation problem via an impulse filter with gradient regularization on the corresponding coefficient map (see Sec. 3 and Sec. 4 of [36]).

from __future__ import print_function
from builtins import input
from builtins import range

import pyfftw   # See https://github.com/pyFFTW/pyFFTW/issues/40
import numpy as np

from sporco import util
from sporco import metric
from sporco import linalg
from sporco import plot
plot.config_notebook_plotting()
from sporco.admm import tvl2
from sporco.admm import cbpdn
from sporco import cuda

# If running in a notebook, try to use wurlitzer so that output from the CUDA
# code will be properly captured in the notebook.
sys_pipes = util.notebook_system_output()

Load a reference image.

img = util.ExampleImages().image('monarch.png', zoom=0.5, scaled=True,
                                 gray=True, idxexp=np.s_[:, 160:672])

Create random mask and apply to reference image to obtain test image. (The call to numpy.random.seed ensures that the pseudo-random noise is reproducible.)

np.random.seed(12345)
frc = 0.5
msk = util.rndmask(img.shape, frc, dtype=np.float32)
imgw = msk * img

Define pad and crop functions.

pn = 8
spad = lambda x:  np.pad(x, pn, mode='symmetric')
zpad = lambda x:  np.pad(x, pn, mode='constant')
crop = lambda x: x[pn:-pn, pn:-pn]

Construct padded mask and test image.

mskp = zpad(msk)
imgwp = spad(imgw)

Load dictionary.

D = util.convdicts()['G:8x8x128']
di = np.zeros(D.shape[0:2] + (1,), dtype=np.float32)
di[0, 0] = 1
Di = np.dstack((di, D))

Set up weights for the \(\ell_1\) norm to disable regularization of the coefficient map corresponding to the impulse filter intended to represent lowpass image components (not to be confused with the AMS impulse filter used to implement spatial masking).

wl1 = np.ones((1,)*2 + (Di.shape[2:]), dtype=np.float32)
wl1[..., 0] = 0.0
wl1i = np.concatenate((wl1, np.zeros(wl1.shape[0:-1] + (1,))), axis=-1)

When representing lowpass image components using an impulse filter together with an \(\ell_2\) norm on the gradient of its coefficient map, we usually want to set the weight array for this norm (specified by the GradWeight option) to disable regularization of all coefficient maps except for the one corresponding to that impulse filter (not to be confused with the AMS impulse filter used to implement spatial masking). In this case set a non-zero value for the weights of the other coefficient maps size this improves performance in this inpainting problem.

#wgr = np.zeros((Di.shape[2]), dtype=np.float32)
wgr = 2e-1 * np.ones((Di.shape[2]), dtype=np.float32)
wgr[0] = 1.0
wgri = np.hstack((wgr, np.zeros((1,))))

Set up admm.cbpdn.ConvBPDNGradReg options.

lmbda = 1e-2
mu = 2e-1
opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': True, 'MaxMainIter': 200,
                    'HighMemSolve': True, 'RelStopTol': 5e-3,
                    'AuxVarObj': False, 'RelaxParam': 1.8,
                    'rho': 5e1*lmbda + 1e-1, 'L1Weight': wl1,
                    'GradWeight': wgr, 'AutoRho': {'Enabled': False,
                    'StdResiduals': False}})

Construct admm.cbpdn.AddMaskSim wrapper for admm.cbpdn.ConvBPDNGradReg and solve via wrapper. If the sporco-cuda extension is installed and a GPU is available, use the CUDA implementation of this combination.

if cuda.device_count() > 0:
    opt['L1Weight'] = wl1
    opt['GradWeight'] = wgr
    ams = None
    print('%s GPU found: running CUDA solver' % cuda.device_name())
    tm = util.Timer()
    with sys_pipes(), util.ContextTimer(tm):
        X = cuda.cbpdngrdmsk(Di, imgwp, mskp, lmbda, mu, opt)
    t = tm.elapsed()
    imgr = crop(np.sum(linalg.fftconv(Di, X), axis=-1))
else:
    opt['L1Weight'] = wl1i
    opt['GradWeight'] = wgri
    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())
Tesla K40c GPU found: running CUDA solver
Itn   Fnc       DFid      Regℓ1     Regℓ2∇     r         s         ρ
--------------------------------------------------------------------------
   0  3.67e+02  1.68e+02  1.91e+04  4.08e+01  5.80e-01  1.48e+00  6.00e-01
   1  2.87e+02  2.70e+01  2.39e+04  1.05e+02  3.81e-01  6.85e-01  6.00e-01
   2  2.71e+02  3.10e+01  2.13e+04  1.34e+02  2.63e-01  9.27e-01  6.00e-01
   3  1.78e+02  1.19e+01  1.47e+04  9.76e+01  1.35e-01  4.55e-01  6.00e-01
   4  1.65e+02  4.61e+00  1.42e+04  9.13e+01  1.06e-01  2.42e-01  6.00e-01
   5  1.44e+02  3.25e+00  1.22e+04  9.17e+01  7.15e-02  2.67e-01  6.00e-01
   6  1.32e+02  3.48e+00  1.11e+04  8.73e+01  5.04e-02  1.97e-01  6.00e-01
   7  1.16e+02  2.55e+00  9.73e+03  8.10e+01  4.18e-02  1.63e-01  6.00e-01
   8  1.08e+02  2.04e+00  9.02e+03  7.70e+01  3.50e-02  1.57e-01  6.00e-01
   9  1.02e+02  2.19e+00  8.47e+03  7.35e+01  3.02e-02  1.42e-01  6.00e-01
  10  9.42e+01  2.10e+00  7.80e+03  7.06e+01  2.69e-02  1.38e-01  6.00e-01
  11  9.18e+01  1.88e+00  7.63e+03  6.78e+01  2.49e-02  1.30e-01  6.00e-01
  12  8.71e+01  1.85e+00  7.22e+03  6.51e+01  2.28e-02  1.25e-01  6.00e-01
  13  8.23e+01  1.77e+00  6.81e+03  6.23e+01  2.12e-02  1.22e-01  6.00e-01
  14  7.87e+01  1.70e+00  6.51e+03  5.98e+01  1.98e-02  1.19e-01  6.00e-01
  15  7.59e+01  1.66e+00  6.27e+03  5.75e+01  1.87e-02  1.15e-01  6.00e-01
  16  7.32e+01  1.60e+00  6.05e+03  5.55e+01  1.77e-02  1.13e-01  6.00e-01
  17  7.01e+01  1.54e+00  5.79e+03  5.35e+01  1.68e-02  1.11e-01  6.00e-01
  18  6.72e+01  1.50e+00  5.54e+03  5.16e+01  1.60e-02  1.09e-01  6.00e-01
  19  6.50e+01  1.46e+00  5.35e+03  4.98e+01  1.53e-02  1.07e-01  6.00e-01
  20  6.30e+01  1.42e+00  5.19e+03  4.81e+01  1.47e-02  1.06e-01  6.00e-01
  21  6.08e+01  1.38e+00  5.02e+03  4.65e+01  1.41e-02  1.04e-01  6.00e-01
  22  5.87e+01  1.34e+00  4.84e+03  4.50e+01  1.35e-02  1.03e-01  6.00e-01
  23  5.69e+01  1.30e+00  4.69e+03  4.35e+01  1.30e-02  1.01e-01  6.00e-01
  24  5.51e+01  1.27e+00  4.54e+03  4.21e+01  1.26e-02  1.00e-01  6.00e-01
  25  5.34e+01  1.24e+00  4.40e+03  4.08e+01  1.21e-02  9.89e-02  6.00e-01
  26  5.26e+01  1.97e+00  4.27e+03  3.96e+01  1.17e-02  9.78e-02  6.00e-01
  27  5.02e+01  1.17e+00  4.14e+03  3.84e+01  1.13e-02  9.68e-02  6.00e-01
  28  4.87e+01  1.14e+00  4.01e+03  3.73e+01  1.10e-02  9.61e-02  6.00e-01
  29  4.73e+01  1.16e+00  3.89e+03  3.62e+01  1.06e-02  9.48e-02  6.00e-01
  30  4.59e+01  1.09e+00  3.77e+03  3.52e+01  1.03e-02  9.39e-02  6.00e-01
  31  4.46e+01  1.06e+00  3.67e+03  3.42e+01  9.97e-03  9.32e-02  6.00e-01
  32  4.34e+01  1.04e+00  3.57e+03  3.33e+01  9.67e-03  9.20e-02  6.00e-01
  33  4.22e+01  1.01e+00  3.47e+03  3.24e+01  9.39e-03  9.10e-02  6.00e-01
  34  4.11e+01  9.85e-01  3.38e+03  3.16e+01  9.12e-03  9.01e-02  6.00e-01
  35  4.01e+01  9.60e-01  3.30e+03  3.08e+01  8.87e-03  8.91e-02  6.00e-01
  36  3.91e+01  9.35e-01  3.22e+03  3.00e+01  8.63e-03  8.81e-02  6.00e-01
  37  3.82e+01  9.10e-01  3.15e+03  2.93e+01  8.39e-03  8.71e-02  6.00e-01
  38  3.74e+01  8.86e-01  3.08e+03  2.87e+01  8.17e-03  8.61e-02  6.00e-01
  39  3.66e+01  8.62e-01  3.01e+03  2.80e+01  7.96e-03  8.51e-02  6.00e-01
  40  3.58e+01  8.39e-01  2.95e+03  2.74e+01  7.75e-03  8.41e-02  6.00e-01
  41  3.52e+01  8.17e-01  2.90e+03  2.69e+01  7.58e-03  8.29e-02  6.00e-01
  42  3.45e+01  7.96e-01  2.85e+03  2.63e+01  7.37e-03  8.19e-02  6.00e-01
  43  3.39e+01  7.75e-01  2.80e+03  2.58e+01  7.19e-03  8.07e-02  6.00e-01
  44  3.33e+01  7.55e-01  2.75e+03  2.54e+01  7.03e-03  7.97e-02  6.00e-01
  45  3.27e+01  7.35e-01  2.70e+03  2.49e+01  6.85e-03  7.84e-02  6.00e-01
  46  3.22e+01  7.17e-01  2.66e+03  2.45e+01  6.68e-03  7.72e-02  6.00e-01
  47  3.17e+01  7.06e-01  2.61e+03  2.41e+01  6.52e-03  7.61e-02  6.00e-01
  48  3.11e+01  6.83e-01  2.57e+03  2.37e+01  6.36e-03  7.50e-02  6.00e-01
  49  3.07e+01  6.68e-01  2.53e+03  2.34e+01  6.21e-03  7.37e-02  6.00e-01
  50  3.02e+01  6.53e-01  2.49e+03  2.31e+01  6.09e-03  7.26e-02  6.00e-01
  51  2.97e+01  6.39e-01  2.45e+03  2.28e+01  5.92e-03  7.13e-02  6.00e-01
  52  2.93e+01  6.26e-01  2.41e+03  2.25e+01  5.78e-03  7.02e-02  6.00e-01
  53  2.88e+01  6.14e-01  2.38e+03  2.22e+01  5.64e-03  6.88e-02  6.00e-01
  54  2.84e+01  6.02e-01  2.34e+03  2.20e+01  5.51e-03  6.77e-02  6.00e-01
  55  2.80e+01  5.91e-01  2.30e+03  2.18e+01  5.37e-03  6.64e-02  6.00e-01
  56  2.76e+01  5.81e-01  2.27e+03  2.16e+01  5.25e-03  6.53e-02  6.00e-01
  57  2.72e+01  5.72e-01  2.23e+03  2.14e+01  5.12e-03  6.41e-02  6.00e-01
  58  2.68e+01  5.62e-01  2.20e+03  2.12e+01  5.00e-03  6.29e-02  6.00e-01
  59  2.64e+01  5.54e-01  2.16e+03  2.11e+01  4.88e-03  6.17e-02  6.00e-01
  60  2.60e+01  5.46e-01  2.13e+03  2.10e+01  4.76e-03  6.05e-02  6.00e-01
  61  2.57e+01  5.38e-01  2.10e+03  2.08e+01  4.66e-03  5.93e-02  6.00e-01
  62  2.53e+01  5.30e-01  2.07e+03  2.07e+01  4.55e-03  5.82e-02  6.00e-01
  63  2.50e+01  5.23e-01  2.04e+03  2.06e+01  4.44e-03  5.70e-02  6.00e-01
  64  2.47e+01  5.16e-01  2.01e+03  2.05e+01  4.34e-03  5.61e-02  6.00e-01
  65  2.44e+01  5.10e-01  1.98e+03  2.04e+01  4.24e-03  5.48e-02  6.00e-01
  66  2.41e+01  5.03e-01  1.95e+03  2.04e+01  4.15e-03  5.37e-02  6.00e-01
  67  2.38e+01  4.97e-01  1.93e+03  2.03e+01  4.05e-03  5.26e-02  6.00e-01
  68  2.36e+01  4.91e-01  1.91e+03  2.02e+01  3.96e-03  5.15e-02  6.00e-01
  69  2.33e+01  4.86e-01  1.88e+03  2.02e+01  3.88e-03  5.06e-02  6.00e-01
  70  2.31e+01  4.80e-01  1.86e+03  2.01e+01  3.79e-03  4.95e-02  6.00e-01
  71  2.29e+01  4.75e-01  1.84e+03  2.00e+01  3.71e-03  4.84e-02  6.00e-01
  72  2.26e+01  4.70e-01  1.82e+03  2.00e+01  3.63e-03  4.75e-02  6.00e-01
  73  2.24e+01  4.66e-01  1.80e+03  2.00e+01  3.55e-03  4.66e-02  6.00e-01
  74  2.22e+01  4.61e-01  1.78e+03  1.99e+01  3.48e-03  4.55e-02  6.00e-01
  75  2.20e+01  4.57e-01  1.76e+03  1.99e+01  3.40e-03  4.45e-02  6.00e-01
  76  2.18e+01  4.53e-01  1.74e+03  1.98e+01  3.33e-03  4.36e-02  6.00e-01
  77  2.16e+01  4.66e-01  1.72e+03  1.98e+01  3.26e-03  4.27e-02  6.00e-01
  78  2.14e+01  4.46e-01  1.70e+03  1.98e+01  3.19e-03  4.20e-02  6.00e-01
  79  2.12e+01  4.43e-01  1.68e+03  1.97e+01  3.12e-03  4.10e-02  6.00e-01
  80  2.10e+01  4.40e-01  1.66e+03  1.97e+01  3.06e-03  4.02e-02  6.00e-01
  81  2.08e+01  4.37e-01  1.64e+03  1.97e+01  3.00e-03  3.94e-02  6.00e-01
  82  2.06e+01  4.34e-01  1.63e+03  1.96e+01  2.93e-03  3.86e-02  6.00e-01
  83  2.05e+01  4.32e-01  1.61e+03  1.96e+01  2.87e-03  3.80e-02  6.00e-01
  84  2.03e+01  4.29e-01  1.59e+03  1.96e+01  2.81e-03  3.72e-02  6.00e-01
  85  2.01e+01  4.27e-01  1.58e+03  1.95e+01  2.75e-03  3.64e-02  6.00e-01
  86  1.99e+01  4.25e-01  1.56e+03  1.95e+01  2.70e-03  3.58e-02  6.00e-01
  87  1.98e+01  4.23e-01  1.54e+03  1.95e+01  2.64e-03  3.51e-02  6.00e-01
  88  1.96e+01  4.21e-01  1.53e+03  1.94e+01  2.59e-03  3.45e-02  6.00e-01
  89  1.94e+01  4.19e-01  1.51e+03  1.94e+01  2.53e-03  3.39e-02  6.00e-01
  90  1.93e+01  4.18e-01  1.50e+03  1.94e+01  2.48e-03  3.33e-02  6.00e-01
  91  1.91e+01  4.16e-01  1.48e+03  1.94e+01  2.43e-03  3.27e-02  6.00e-01
  92  1.89e+01  4.15e-01  1.47e+03  1.93e+01  2.38e-03  3.22e-02  6.00e-01
  93  1.88e+01  4.13e-01  1.45e+03  1.93e+01  2.33e-03  3.16e-02  6.00e-01
  94  1.86e+01  4.12e-01  1.44e+03  1.93e+01  2.28e-03  3.11e-02  6.00e-01
  95  1.85e+01  4.10e-01  1.42e+03  1.92e+01  2.24e-03  3.05e-02  6.00e-01
  96  1.84e+01  4.24e-01  1.41e+03  1.92e+01  2.19e-03  3.00e-02  6.00e-01
  97  1.82e+01  4.08e-01  1.40e+03  1.91e+01  2.15e-03  2.94e-02  6.00e-01
  98  1.81e+01  4.07e-01  1.39e+03  1.91e+01  2.11e-03  2.89e-02  6.00e-01
  99  1.80e+01  4.06e-01  1.38e+03  1.91e+01  2.06e-03  2.83e-02  6.00e-01
 100  1.79e+01  4.05e-01  1.37e+03  1.90e+01  2.03e-03  2.78e-02  6.00e-01
 101  1.78e+01  4.15e-01  1.36e+03  1.90e+01  1.99e-03  2.72e-02  6.00e-01
 102  1.77e+01  4.02e-01  1.35e+03  1.90e+01  1.95e-03  2.67e-02  6.00e-01
 103  1.76e+01  4.01e-01  1.34e+03  1.89e+01  1.92e-03  2.62e-02  6.00e-01
 104  1.75e+01  4.01e-01  1.34e+03  1.89e+01  1.88e-03  2.56e-02  6.00e-01
 105  1.75e+01  4.00e-01  1.33e+03  1.89e+01  1.85e-03  2.51e-02  6.00e-01
 106  1.74e+01  3.99e-01  1.32e+03  1.88e+01  1.81e-03  2.45e-02  6.00e-01
 107  1.73e+01  3.98e-01  1.32e+03  1.88e+01  1.78e-03  2.40e-02  6.00e-01
 108  1.72e+01  3.97e-01  1.31e+03  1.87e+01  1.75e-03  2.35e-02  6.00e-01
 109  1.71e+01  3.97e-01  1.30e+03  1.87e+01  1.72e-03  2.30e-02  6.00e-01
 110  1.71e+01  3.96e-01  1.29e+03  1.87e+01  1.68e-03  2.26e-02  6.00e-01
 111  1.70e+01  3.96e-01  1.29e+03  1.86e+01  1.65e-03  2.22e-02  6.00e-01
 112  1.69e+01  3.95e-01  1.28e+03  1.86e+01  1.62e-03  2.17e-02  6.00e-01
 113  1.68e+01  3.95e-01  1.27e+03  1.86e+01  1.59e-03  2.13e-02  6.00e-01
 114  1.67e+01  3.95e-01  1.26e+03  1.85e+01  1.56e-03  2.09e-02  6.00e-01
 115  1.67e+01  3.94e-01  1.26e+03  1.85e+01  1.53e-03  2.05e-02  6.00e-01
 116  1.66e+01  3.94e-01  1.25e+03  1.85e+01  1.50e-03  2.02e-02  6.00e-01
 117  1.65e+01  3.94e-01  1.24e+03  1.84e+01  1.47e-03  1.99e-02  6.00e-01
 118  1.64e+01  3.94e-01  1.23e+03  1.84e+01  1.45e-03  1.96e-02  6.00e-01
 119  1.63e+01  3.93e-01  1.23e+03  1.84e+01  1.42e-03  1.92e-02  6.00e-01
 120  1.63e+01  3.93e-01  1.22e+03  1.83e+01  1.39e-03  1.89e-02  6.00e-01
 121  1.62e+01  3.93e-01  1.21e+03  1.83e+01  1.36e-03  1.87e-02  6.00e-01
 122  1.61e+01  3.93e-01  1.21e+03  1.83e+01  1.34e-03  1.84e-02  6.00e-01
 123  1.60e+01  3.93e-01  1.20e+03  1.83e+01  1.31e-03  1.81e-02  6.00e-01
 124  1.60e+01  3.93e-01  1.19e+03  1.82e+01  1.29e-03  1.78e-02  6.00e-01
 125  1.59e+01  3.93e-01  1.19e+03  1.82e+01  1.27e-03  1.76e-02  6.00e-01
 126  1.59e+01  3.92e-01  1.18e+03  1.82e+01  1.25e-03  1.73e-02  6.00e-01
 127  1.58e+01  3.92e-01  1.18e+03  1.82e+01  1.22e-03  1.70e-02  6.00e-01
 128  1.57e+01  3.92e-01  1.17e+03  1.81e+01  1.20e-03  1.68e-02  6.00e-01
 129  1.57e+01  3.92e-01  1.17e+03  1.81e+01  1.18e-03  1.65e-02  6.00e-01
 130  1.56e+01  3.92e-01  1.16e+03  1.81e+01  1.16e-03  1.62e-02  6.00e-01
 131  1.56e+01  3.92e-01  1.16e+03  1.81e+01  1.15e-03  1.60e-02  6.00e-01
 132  1.55e+01  3.91e-01  1.15e+03  1.80e+01  1.13e-03  1.57e-02  6.00e-01
 133  1.55e+01  3.91e-01  1.15e+03  1.80e+01  1.11e-03  1.55e-02  6.00e-01
 134  1.55e+01  3.91e-01  1.15e+03  1.80e+01  1.09e-03  1.53e-02  6.00e-01
 135  1.54e+01  3.91e-01  1.14e+03  1.80e+01  1.08e-03  1.50e-02  6.00e-01
 136  1.54e+01  3.91e-01  1.14e+03  1.79e+01  1.06e-03  1.49e-02  6.00e-01
 137  1.53e+01  3.90e-01  1.13e+03  1.79e+01  1.04e-03  1.46e-02  6.00e-01
 138  1.53e+01  3.90e-01  1.13e+03  1.79e+01  1.03e-03  1.44e-02  6.00e-01
 139  1.52e+01  3.90e-01  1.13e+03  1.79e+01  1.01e-03  1.42e-02  6.00e-01
 140  1.52e+01  3.98e-01  1.12e+03  1.79e+01  9.96e-04  1.40e-02  6.00e-01
 141  1.51e+01  3.90e-01  1.12e+03  1.78e+01  9.81e-04  1.38e-02  6.00e-01
 142  1.51e+01  3.89e-01  1.12e+03  1.78e+01  9.68e-04  1.36e-02  6.00e-01
 143  1.51e+01  3.89e-01  1.11e+03  1.78e+01  9.52e-04  1.34e-02  6.00e-01
 144  1.50e+01  3.89e-01  1.11e+03  1.78e+01  9.38e-04  1.33e-02  6.00e-01
 145  1.50e+01  3.89e-01  1.10e+03  1.78e+01  9.24e-04  1.31e-02  6.00e-01
 146  1.49e+01  3.88e-01  1.10e+03  1.77e+01  9.10e-04  1.29e-02  6.00e-01
 147  1.49e+01  3.88e-01  1.10e+03  1.77e+01  8.97e-04  1.27e-02  6.00e-01
 148  1.49e+01  3.88e-01  1.09e+03  1.77e+01  8.84e-04  1.25e-02  6.00e-01
 149  1.48e+01  3.88e-01  1.09e+03  1.77e+01  8.71e-04  1.24e-02  6.00e-01
 150  1.48e+01  3.88e-01  1.09e+03  1.76e+01  8.58e-04  1.22e-02  6.00e-01
 151  1.48e+01  3.87e-01  1.08e+03  1.76e+01  8.45e-04  1.21e-02  6.00e-01
 152  1.47e+01  3.87e-01  1.08e+03  1.76e+01  8.33e-04  1.19e-02  6.00e-01
 153  1.47e+01  4.33e-01  1.08e+03  1.76e+01  8.20e-04  1.18e-02  6.00e-01
 154  1.46e+01  3.87e-01  1.07e+03  1.75e+01  8.08e-04  1.16e-02  6.00e-01
 155  1.46e+01  3.87e-01  1.07e+03  1.75e+01  7.96e-04  1.15e-02  6.00e-01
 156  1.46e+01  3.95e-01  1.07e+03  1.75e+01  7.85e-04  1.14e-02  6.00e-01
 157  1.45e+01  3.86e-01  1.07e+03  1.75e+01  7.73e-04  1.12e-02  6.00e-01
 158  1.45e+01  3.86e-01  1.06e+03  1.75e+01  7.62e-04  1.11e-02  6.00e-01
 159  1.45e+01  3.86e-01  1.06e+03  1.74e+01  7.51e-04  1.10e-02  6.00e-01
 160  1.44e+01  3.86e-01  1.06e+03  1.74e+01  7.41e-04  1.09e-02  6.00e-01
 161  1.44e+01  3.86e-01  1.06e+03  1.74e+01  7.31e-04  1.07e-02  6.00e-01
 162  1.44e+01  3.86e-01  1.05e+03  1.74e+01  7.20e-04  1.06e-02  6.00e-01
 163  1.44e+01  3.86e-01  1.05e+03  1.73e+01  7.11e-04  1.05e-02  6.00e-01
 164  1.43e+01  3.86e-01  1.05e+03  1.73e+01  7.01e-04  1.04e-02  6.00e-01
 165  1.43e+01  3.85e-01  1.05e+03  1.73e+01  6.92e-04  1.03e-02  6.00e-01
 166  1.43e+01  3.85e-01  1.04e+03  1.73e+01  6.82e-04  1.01e-02  6.00e-01
 167  1.43e+01  3.85e-01  1.04e+03  1.73e+01  6.74e-04  1.00e-02  6.00e-01
 168  1.42e+01  3.85e-01  1.04e+03  1.72e+01  6.65e-04  9.92e-03  6.00e-01
 169  1.42e+01  3.85e-01  1.04e+03  1.72e+01  6.57e-04  9.82e-03  6.00e-01
 170  1.42e+01  3.85e-01  1.04e+03  1.72e+01  6.48e-04  9.69e-03  6.00e-01
 171  1.42e+01  3.85e-01  1.03e+03  1.72e+01  6.40e-04  9.58e-03  6.00e-01
 172  1.41e+01  3.85e-01  1.03e+03  1.72e+01  6.33e-04  9.47e-03  6.00e-01
 173  1.41e+01  3.85e-01  1.03e+03  1.71e+01  6.25e-04  9.37e-03  6.00e-01
 174  1.41e+01  3.85e-01  1.03e+03  1.71e+01  6.17e-04  9.26e-03  6.00e-01
 175  1.41e+01  3.85e-01  1.03e+03  1.71e+01  6.09e-04  9.15e-03  6.00e-01
 176  1.41e+01  3.85e-01  1.03e+03  1.71e+01  6.02e-04  9.04e-03  6.00e-01
 177  1.40e+01  3.85e-01  1.02e+03  1.71e+01  5.95e-04  8.94e-03  6.00e-01
 178  1.40e+01  3.84e-01  1.02e+03  1.70e+01  5.87e-04  8.84e-03  6.00e-01
 179  1.40e+01  3.97e-01  1.02e+03  1.70e+01  5.80e-04  8.74e-03  6.00e-01
 180  1.40e+01  3.84e-01  1.02e+03  1.70e+01  5.73e-04  8.65e-03  6.00e-01
 181  1.40e+01  3.84e-01  1.02e+03  1.70e+01  5.65e-04  8.55e-03  6.00e-01
 182  1.39e+01  3.84e-01  1.02e+03  1.70e+01  5.58e-04  8.46e-03  6.00e-01
 183  1.39e+01  3.84e-01  1.01e+03  1.69e+01  5.51e-04  8.37e-03  6.00e-01
 184  1.39e+01  3.84e-01  1.01e+03  1.69e+01  5.44e-04  8.30e-03  6.00e-01
 185  1.39e+01  3.84e-01  1.01e+03  1.69e+01  5.37e-04  8.21e-03  6.00e-01
 186  1.39e+01  3.84e-01  1.01e+03  1.69e+01  5.30e-04  8.15e-03  6.00e-01
 187  1.38e+01  3.84e-01  1.01e+03  1.69e+01  5.24e-04  8.04e-03  6.00e-01
 188  1.38e+01  3.84e-01  1.01e+03  1.69e+01  5.17e-04  7.98e-03  6.00e-01
 189  1.38e+01  3.84e-01  1.00e+03  1.69e+01  5.10e-04  7.90e-03  6.00e-01
 190  1.38e+01  3.84e-01  1.00e+03  1.68e+01  5.04e-04  7.81e-03  6.00e-01
 191  1.38e+01  3.84e-01  1.00e+03  1.68e+01  4.98e-04  7.74e-03  6.00e-01
 192  1.37e+01  3.84e-01  1.00e+03  1.68e+01  4.91e-04  7.66e-03  6.00e-01
 193  1.37e+01  3.84e-01  9.99e+02  1.68e+01  4.86e-04  7.58e-03  6.00e-01
 194  1.37e+01  3.83e-01  9.98e+02  1.68e+01  4.80e-04  7.51e-03  6.00e-01
 195  1.37e+01  3.83e-01  9.96e+02  1.68e+01  4.74e-04  7.43e-03  6.00e-01
 196  1.37e+01  3.83e-01  9.95e+02  1.68e+01  4.69e-04  7.36e-03  6.00e-01
 197  1.37e+01  3.83e-01  9.94e+02  1.67e+01  4.63e-04  7.28e-03  6.00e-01
 198  1.37e+01  3.83e-01  9.93e+02  1.67e+01  4.58e-04  7.20e-03  6.00e-01
 199  1.36e+01  3.83e-01  9.92e+02  1.67e+01  4.53e-04  7.13e-03  6.00e-01
--------------------------------------------------------------------------

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))
AddMaskSim wrapped ConvBPDN solve time: 3.37s
Corrupted image PSNR:  9.17 dB
Recovered image PSNR: 25.51 dB

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()
../../_images/cbpdn_ams_grd_gry_23_0.png

Display lowpass component and sparse representation

fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(X[..., 0], cmap=plot.cm.Blues, title='Lowpass component', fig=fig)
plot.subplot(1, 2, 2)
plot.imview(np.sum(abs(X[..., 1:]).squeeze(), axis=-1), cmap=plot.cm.Blues,
            title='Sparse representation', fig=fig)
fig.show()
../../_images/cbpdn_ams_grd_gry_25_0.png

Plot functional value, residuals, and rho (not available if GPU implementation used).

if ams is not None:
    its = ams.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(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()