Ejemplo n.º 1
0
        title='Surface Plot Example', cntr=5, fgsz=(7, 6))


"""
Plot a contour plot of the same surface.
"""

plot.contour(z, x, y, xlbl='x', ylbl='y', title='Contour Plot Example',
            fgsz=(6, 5))


"""
We can also plot within subplots of the same figure.
"""

fig, ax = plot.subplots(nrows=1, ncols=2, figsize=(12.1, 5))
fig.suptitle('Figure Title', fontsize=14)
plot.surf(z, x, y, xlbl='x', ylbl='y', zlbl='z', title='Surface Plot Example',
        fig=fig, ax=ax[0])
plot.contour(z, x, y, xlbl='x', ylbl='y', title='Contour Plot Example',
        fig=fig, ax=ax[1])
fig.show()


"""
Load an example colour image and create a corresponding grayscale version.
"""

imgc = util.ExampleImages().image('kodim23.png', scaled=True,
                                idxexp=np.s_[150:500, 30:380])
imgg = util.rgb2gray(imgc)
Ejemplo n.º 2
0

"""
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()


"""
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)
Ejemplo n.º 3
0
"""
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)
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()
"""
Display sparse representation components as sums of absolute values of coefficient maps for $X$, $DX$, and $XB$.
"""

fig, ax = plot.subplots(nrows=2, ncols=2, figsize=(14, 14))
plot.imview(gamma(
    np.sum(abs(X[..., 0:3, :, :]), axis=b.cri.axisM).squeeze(), 0.5),
Ejemplo n.º 4
0

"""
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()



"""
The previous method gave good results, but the weight on the filter representing the impulse noise is an additional parameter that has to be tuned. This parameter can be avoided by switching to an $\ell_1$ data fidelity term instead of including dictionary filters to represent the impulse noise, as in the problem :cite:`wohlberg-2016-convolutional2`

  $$\mathrm{argmin}_{\{\mathbf{x}_m\}} \;
  \left \|  \sum_m \mathbf{d}_m * \mathbf{x}_m - \mathbf{s}
  \right \|_1 + \lambda \sum_m \| \mathbf{x}_m \|_1 \;.$$
Ejemplo n.º 5
0
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])
plot.imview(imgp,
            title='PPP demoisac: %.2f (dB)' % metric.psnr(img, imgp),
            fig=fig,
            ax=ax[2])
fig.show()

# Wait for enter on keyboard
input()
Ejemplo n.º 6
0
 def test_03(self):
     fig, ax = plot.subplots(nrows=1, ncols=1)
     plot.surf(self.z, title='Surf Test', xlbl='x', ylbl='y', zlbl='z',
               elev=0.0, fig=fig, ax=ax)
     plot.close()
Ejemplo n.º 7
0
          + complex(0, 1) * sinesignal.generate_sine_wave_no(N, A, 5, fs, 0)

s_noise = s_clean + noise

s_clean = s_clean[:, np.newaxis]
s_noise = s_noise[:, np.newaxis]

Maxiter = 200
opt_par = cbpdn.ConvBPDN.Options({'Verbose': True, 'MaxMainIter': Maxiter,
                                  'RelStopTol': 1e-4, 'AuxVarObj': False,
                                  'AutoRho': {'Enabled': True}})

# solve with real valued signal with real valued dictionary
b_r = cbpdn.ConvBPDN(D0.real, s_noise.real, lmbda_0, opt=opt_par, dimK=None, dimN=dimN)
x_r = b_r.solve()
fig, ax = plot.subplots(nrows=2, ncols=3, sharex=True, sharey=True, figsize=(18, 8))

rec_r = b_r.reconstruct().squeeze()
fig.suptitle('real value solver ' + str(np.count_nonzero(x_r) * 100 / x_r.size) + '% non zero elements', fontsize=14)
plot.plot(s_clean.real, title='clean(real)', fig=fig, ax=ax[0, 0])
plot.plot(s_clean.imag, title='clean(imag)', fig=fig, ax=ax[1, 0])

plot.plot(s_noise.real, title='corrupted(real)', fig=fig, ax=ax[0, 1])
plot.plot(s_noise.imag, title='corrupted(imag)', fig=fig, ax=ax[1, 1])

plot.plot(rec_r.real, title='reconstructed(real)', fig=fig, ax=ax[0, 2])
plot.plot(rec_r.imag, title='reconstructed(imag)', fig=fig, ax=ax[1, 2])

fig.show()
# solve with a complex valued signal with complex valued dictionary
b_c = comcbpdn.ComplexConvBPDN(D0, s_noise, lmbda_0, opt_par, None, dimN)