コード例 #1
0
def output_Image(flag, Img, file, path):
    if flag == 0:
        fig1 = plot.figure()
        plot.subplot(1, 1, 1)
        plot.imview(util.tiledict(Img[0]),
                    title='Initial Dctionary(Layer1)',
                    fig=fig1)
        fig1.savefig(path + '\\' + file + '(Layer1).png')

        fig2 = plot.figure()
        plot.subplot(1, 1, 1)
        plot.imview(util.tiledict(Img[1]),
                    title='Initial Dctionary(Layer2)',
                    fig=fig2)
        fig2.savefig(path + '\\' + file + '(Layer2).png')

    elif flag == 1:
        fig3 = plot.figure()
        for i in range(len(Img)):
            plot.subplot(3, 3, i + 1)
            plot.imview(util.tiledict(Img[i]), title='', fig=fig3)
        fig3.savefig(path + '\\' + file + '.png')

    elif flag == 2:
        fig4 = plot.figure()
        for i in range(len(Img)):
            plot.subplot(3, 3, i + 1)
            plot.imview(util.tiledict(Img[i]), title='', fig=fig4)
        fig4.savefig(path + '\\' + file + '.png')

    elif flag == 3:
        fig_t = plot.figure()
        for i in range(9):
            plot.subplot(1, 1, 1)
            plot.imview(util.tiledict(Img), title='', fig=fig_t)
        fig_t.savefig(path + '\\' + file + '.png')
コード例 #2
0
ファイル: plot.py プロジェクト: bwohlberg/sporco-extra
def plot_solver_stats(pe):
    """Plot iteration statistics for a :class:`.cdl.PSFEstimator` solve.

    Parameters
    ----------
    pe : :class:`.cdl.PSFEstimator`
        Solver object for which solver iteration stats are to be plotted

    Returns
    -------
    :class:`matplotlib.figure.Figure` object
        Figure object for this figure
    """

    itsx = pe.slvX.getitstat()
    itsg = pe.slvG.getitstat()
    fig = plot.figure(figsize=(20, 5))
    fig.suptitle('Solver iteration statistics')
    plot.subplot(1, 3, 1)
    N = min(len(itsx.ObjFun), len(itsg.DFid))
    fnvl = np.vstack(
        (itsx.ObjFun[-N:], itsg.ObjFun[-N:], itsx.DFid[-N:], itsg.DFid[-N:])).T
    lgnd = ('X Func.', 'G Func,', 'X D. Fid.', 'G D. Fid.')
    plot.plot(fnvl,
              ptyp='semilogy',
              xlbl='Iterations',
              ylbl='Functional',
              lgnd=lgnd,
              fig=fig)
    plot.subplot(1, 3, 2)
    plot.plot(np.vstack((itsx.PrimalRsdl, itsx.DualRsdl)).T,
              ptyp='semilogy',
              xlbl='Iterations',
              ylbl='X Residual',
              lgnd=['Primal', 'Dual'],
              fig=fig)
    plot.subplot(1, 3, 3)
    if hasattr(itsg, 'PrimalRsdl'):
        plot.plot(np.vstack((itsg.PrimalRsdl, itsg.DualRsdl)).T,
                  ptyp='semilogy',
                  xlbl='Iterations',
                  ylbl='G Residual',
                  lgnd=['Primal', 'Dual'],
                  fig=fig)
    else:
        plot.plot(itsg.Rsdl,
                  ptyp='semilogy',
                  xlbl='Iterations',
                  ylbl='G Residual',
                  fig=fig)
    fig.show()
    return fig
コード例 #3
0
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.
"""

its = b.getitstat()
fig = plot.figure(figsize=(20, 5))
plot.subplot(1, 3, 1)
plot.plot(its.ObjFun, fgrf=fig, xlbl='Iterations', ylbl='Functional')
plot.subplot(1, 3, 2)
コード例 #4
0
ファイル: bpdn.py プロジェクト: bwohlberg/sporco
"""
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()



# Wait for enter on keyboard
コード例 #5
0
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)
fig.show()
コード例 #6
0
        'rho': 50.0 * lmbda + 0.5
    },
    'CCMOD': {
        'ZeroMean': True
    }
})
Wr = np.reshape(W, W.shape[0:3] + (W.shape[3], 1))
d2 = cbpdndl.ConvBPDNMaskDcplDictLearn(D0, shpw, lmbda, Wr, opt2)
D2 = d2.solve()

# Reconstruct from ConvBPDNMaskDcplDictLearn solution
sr2 = d2.reconstruct()[:-Npr, :-Npc].squeeze() + sl

# Compare dictionaries
fig1 = plot.figure(1, figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D1.squeeze()),
            fgrf=fig1,
            title='Without Mask Decoupling')
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D2.squeeze()),
            fgrf=fig1,
            title='With Mask Decoupling')
fig1.show()

# Display reference and test images (with unmasked lowpass component)
fig2 = plot.figure(2, figsize=(14, 14))
plot.subplot(2, 2, 1)
plot.imview(S[..., 0], fgrf=fig2, title='Reference')
plot.subplot(2, 2, 2)
plot.imview(shpw[:-Npr, :-Npc, :, 0] + sl[..., 0], fgrf=fig2, title='Test')
コード例 #7
0
ファイル: cprjl1_gry.py プロジェクト: bwohlberg/sporco
"""
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)
plot.subplot(1, 2, 2)
コード例 #8
0
a = cbpdn.ConvBPDN(D, pad(imgnh), lmbda, opt1, dimK=0)
b = cbpdntv.ConvBPDNScalarTV(D, pad(imgnh), lmbda, mu, opt2)
c = cbpdntv.ConvBPDNVectorTV(D, pad(imgnh), lmbda, mu, opt3)
X1 = a.solve()
X2 = b.solve()
X3 = c.solve()
imgdp1 = a.reconstruct().squeeze()
imgd1 = np.clip(crop(imgdp1) + imgnl, 0, 1)

imgdp2 = b.reconstruct().squeeze()
imgd2 = np.clip(crop(imgdp2) + imgnl, 0, 1)

imgdp3 = c.reconstruct().squeeze()
imgd3 = np.clip(crop(imgdp3) + imgnl, 0, 1)
print("ConvBPDN solve time: %5.2f s" % b.timer.elapsed('solve'))
print("Noisy image PSNR:    %5.2f dB" % sm.psnr(img, imgn))
print("bpdn PSNR: %5.2f dB" % sm.psnr(img, imgd1))
print("scalar image PSNR: %5.2f dB" % sm.psnr(img, imgd2))
print("vector image PSNR: %5.2f dB" % sm.psnr(img, imgd3))
fig = plot.figure(figsize=(21, 21))
plot.subplot(2, 3, 1)
plot.imview(img, title='Reference', fig=fig)
plot.subplot(2, 3, 2)
plot.imview(imgn, title='Noisy', fig=fig)
plot.subplot(2, 3, 3)
plot.imview(imgd1, title='Conv bpdn', fig=fig)
plot.subplot(2, 3, 4)
plot.imview(imgd2, title='scalar TV', fig=fig)
plot.subplot(2, 3, 5)
plot.imview(imgd3, title='vector TV', fig=fig)
fig.show()
コード例 #9
0
                          dimK=0)
X = b.solve()
print("ConvBPDN 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()
"""
Show activation of grouped elements column-wise for first four groups of both schemes.  As mu is lowered, the vertical pairs should look more and more similar.  You will likely need to zoom in to see the activations clearly.  In general, you should observe that the second-scheme pairs should have more similar-looking activations than first-scheme pairs, proportional to mu of course.
"""

fig = plot.figure(figsize=(14, 10))
for i in range(4):
    plot.subplot(3, 4, i + 1)
    plot.imview(abs(X[:, :, :, :, i]).squeeze(),
コード例 #10
0
ファイル: parcbpdn_md_gry.py プロジェクト: bwohlberg/sporco
"""
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()


"""
Display lowpass component and sparse representation
コード例 #11
0
                          dimK=0)
X = b.solve()
print("ConvBPDN 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()
"""
Show activation of grouped elements column-wise for first four groups.  As mu is lowered, the vertical pairs should look more and more similar.  You will likely need to zoom in to see the activations clearly.
"""

fig = plot.figure(figsize=(14, 7))
for i in range(4):
    plot.subplot(2, 4, i + 1)
    plot.imview(abs(X[:, :, :, :, i]).squeeze(),
コード例 #12
0
ファイル: cbpdnin_msc.py プロジェクト: bwohlberg/sporco-extra
Load example piano piece.
"""

audio, fs = librosa.load(os.path.join('data',
    'MAPS_MUS-deb_clai_ENSTDkCl_excerpt.wav'), 16000)


"""
Load dictionary and display it. Grouped elements are displayed on the same axis.
"""

M = 4
D = np.load(os.path.join('data', 'pianodict.npz'))['elems']
fig = plot.figure(figsize=(10, 16))
for i in range(24):
    plot.subplot(8, 3, i + 1, title=f'{librosa.midi_to_note(i+60)}',
                 ylim=[-6, 6])
    plot.gca().get_xaxis().set_visible(False)
    plot.gca().get_yaxis().set_visible(False)
    plot.gca().set_frame_on(False)
    for k in range(M):
        plot.plot(D[M*(i+1)-k-1], fig=fig)
fig.show()


"""
Set :class:`.admm.cbpdn.ConvBPDNInhib` solver options.
"""

lmbda = 1e-1
mu = 1e1
gamma = 1e0