コード例 #1
0
def deconvolution(f0, kernel, scale, options, lmbd=0.01):

    if scale==0:
        return f0

    # define wavelet transform and inverse wavelet transform functions
    PsiS = lambda f: perform_wavelet_transf(f,3, +1, ti=1)
    Psi  = lambda a:  perform_wavelet_transf(a,3, -1,ti=1)

    #define the soft threshold function applied in the wavelet domain for the optimization
    SoftThresh = lambda x,T: np.multiply(x,np.maximum(0, 1-np.divide(T,np.maximum(np.abs(x),1e-10))))
    SoftThreshPsi = lambda f,T: Psi(SoftThresh(PsiS(f), T))

    #the linear blur operation
    Phi = lambda x: kernel(x, scale)

    #optimization
    #lmbd = 0.01
    tau = 1.5
    niter = 50
    a = PsiS(f0)
    for iter in range(niter):
        #if(options['verbose']): print(cost(f0, Psi(a), Phi))

        #gradient step
        a = np.add(a, tau*PsiS(Phi(f0-Phi(Psi(a)))))
        #soft-threshold step
        a = SoftThresh(a, lmbd*tau )

    return Psi(a)
コード例 #2
0
def deconvolution_adaptativeLambda(f, kernel, scale, options):

    # define wavelet transform and inverse wavelet transform functions
    PsiS = lambda f: perform_wavelet_transf(f, 3, +1, ti=1)
    Psi = lambda a: perform_wavelet_transf(a, 3, -1, ti=1)

    #define the soft threshold function applied in the wavelet domain for the optimization
    SoftThresh = lambda x, T: np.multiply(
        x, np.maximum(0, 1 - np.divide(T, np.maximum(np.abs(x), 1e-10))))
    SoftThreshPsi = lambda f, T: Psi(SoftThresh(PsiS(f), T))

    #the linear blur operation
    Phi = lambda x: kernel(x, scale)

    lmbds = np.exp(np.linspace(-11, -2, 10))
    W = np.zeros(lmbds.shape)
    for i, lmbd in enumerate(lmbds):
        #optimization
        #lmbd = 0.01
        tau = 1.5
        niter = 20
        a = PsiS(f0)  #np.zeros(PsiS(f0).shape)
        for iter in range(niter):
            #if(options['verbose']): print(cost(f0, Psi(a), Phi))

            #gradient step
            a = np.add(a, tau * PsiS(Phi(f0 - Phi(Psi(a)))))
            #soft-threshold step
            a = SoftThresh(a, lmbd * tau)

            #imageplot(Psi(a)-f0, 'Image')
            #plt.show()

        W[i] = whiteness(Phi(Psi(a)) - f0)
        print("Lambda : " + str(lmbd))
        print("Residual whiteness : " + str(whiteness(Phi(Psi(a)) - f0)))
        print()
        #print("SSD : " + str(SSD(Phi(Psi(a)),f0)))

    lmbd = lmbds[np.argmin(W)]
    print("Choosen lambda : " + str(lmbd))
    tau = 1.5
    niter = 20
    a = PsiS(f0)  #np.zeros(PsiS(f0).shape)
    for iter in range(niter):
        #gradient step
        a = np.add(a, tau * PsiS(Phi(f0 - Phi(Psi(a)))))
        #soft-threshold step
        a = SoftThresh(a, lmbd * tau)

    return Psi(a)
コード例 #3
0
def trans_wavelet():

    global fbi
    n = 1024
    f0 = rescale(load_image(fbi, n))
    sigma = 0.15
    f = f0 + sigma*random.standard_normal((n,n))
    Jmin = 8
    wav  = lambda f  : perform_wavelet_transf(f, Jmin, +1)
    iwav = lambda fw : perform_wavelet_transf(fw, Jmin, -1)

    plt.figure(figsize=(10,10))
    plot_wavelet(wav(f), Jmin)
    plt.show()
コード例 #4
0
def deconvolution_3PlanesDecoupled(f0, kernel, C, scales, options, lmbd=0.01):

    # define wavelet transform and inverse wavelet transform functions
    PsiS = lambda f: perform_wavelet_transf(f,3, +1, ti=1)
    Psi  = lambda a:  perform_wavelet_transf(a,3, -1,ti=1)

    #define the soft threshold function applied in the wavelet domain for the optimization
    SoftThresh = lambda x,T: np.multiply(x,np.maximum(0, 1-np.divide(T,np.maximum(np.abs(x),1e-10))))
    SoftThreshPsi = lambda f,T: Psi(SoftThresh(PsiS(f), T))

    #the linear blur operation
    Phi0 = lambda x: kernel(x, scales[0])
    Phi1 = lambda x: kernel(x, scales[1])
    Phi2 = lambda x: kernel(x, scales[2])

    #optimization
    tau = 1.5
    niter = 20
    print(0)
    fc0 = np.mean(f0)*np.ones(f0.shape); fc0[C==0] = f0[C==0]
    a0 = PsiS(fc0)
    for iter in range(niter):
        #gradient step
        a0 = np.add(a0, tau*PsiS(Phi0(( (fc0-Phi0(Psi(a0))) ))))
        #soft-threshold step
        a0 = SoftThresh(a0, lmbd*tau )

    print(1)
    fc1 = np.mean(f0)*np.ones(f0.shape); fc1[C==1] = f0[C==1]
    a1 = PsiS(fc1)
    for iter in range(niter):
        #gradient step
        a1 = np.add(a1, tau*PsiS(Phi1(( (fc1-Phi1(Psi(a1))) ))))
        #soft-threshold step
        a1 = SoftThresh(a1, lmbd*tau )

    print(2)
    fc2 = np.mean(f0)*np.ones(f0.shape); fc2[C==2] = f0[C==2]
    a2 = PsiS(fc2)
    for iter in range(niter):
        #gradient step
        a2 = np.add(a2, tau*PsiS(Phi2(( (fc2-Phi2(Psi(a2))) ))))
        #soft-threshold step
        a2 = SoftThresh(a2, lmbd*tau )

    return Psi(a0)+Psi(a1)+Psi(a2)
コード例 #5
0
def deconvolution_3PlanesFull(f0, kernel, C, scales, options, lmbd=0.01):

    # define wavelet transform and inverse wavelet transform functions
    PsiS = lambda f: perform_wavelet_transf(f,3, +1, ti=1)
    Psi  = lambda a:  perform_wavelet_transf(a,3, -1,ti=1)

    #define the soft threshold function applied in the wavelet domain for the optimization
    SoftThresh = lambda x,T: np.multiply(x,np.maximum(0, 1-np.divide(T,np.maximum(np.abs(x),1e-10))))
    SoftThreshPsi = lambda f,T: Psi(SoftThresh(PsiS(f), T))

    #the linear blur operation
    Phi0 = lambda x: kernel(x, scales[0])
    Phi1 = lambda x: kernel(x, scales[1])
    Phi2 = lambda x: kernel(x, scales[2])

    #optimization
    #lmbd = 0.01
    tau = 1.5
    niter = 20
    a = PsiS(f0)
    for iter in range(niter):
        #if(options['verbose']): print(cost(f0, Psi(a), Phi))
        print(iter)

        #gradient step
        I = Psi(a)
        I0 = np.zeros(I.shape); I0[C==0] = I[C==0]
        I1 = np.zeros(I.shape); I1[C==1] = I[C==1]
        I2 = np.zeros(I.shape); I2[C==2] = I[C==2]
        DI = f0- (Phi0(I0)+Phi1(I1)+Phi2(I2))
        DIb = np.zeros(DI.shape)
        DIb[C==0] = Phi0(DI)[C==0]
        DIb[C==1] = Phi1(DI)[C==1]
        DIb[C==2] = Phi2(DI)[C==2]
        a = np.add(a, tau*PsiS(DIb))
        #soft-threshold step
        a = SoftThresh(a, lmbd*tau )

        I = Psi(a)
        I0 = np.zeros(I.shape); I0[C==0] = I[C==0]
        I1 = np.zeros(I.shape); I1[C==1] = I[C==1]
        I2 = np.zeros(I.shape); I2[C==2] = I[C==2]
        Ib = (Phi0(I0)+Phi1(I1)+Phi2(I2))

    return Psi(a)
コード例 #6
0
def deconvolution(f0, kernel, scale, options, lmbd=0.01):
    print(scale)
    # define wavelet transform and inverse wavelet transform functions
    PsiS = lambda f: perform_wavelet_transf(f, 3, +1, ti=1)
    Psi = lambda a: perform_wavelet_transf(a, 3, -1, ti=1)

    #define the soft threshold function applied in the wavelet domain for the optimization
    SoftThresh = lambda x, T: np.multiply(
        x, np.maximum(0, 1 - np.divide(T, np.maximum(np.abs(x), 1e-10))))
    SoftThreshPsi = lambda f, T: Psi(SoftThresh(PsiS(f), T))

    #the linear blur operation
    Phi = lambda x: kernel(x, scale)

    #optimization
    '''
    a_ = PsiS(f0)
    a_ = a_/np.sqrt(np.sum(a_**2))
    for i in range(10):
        a_ = PsiS(Phi(Phi(Psi(a_))))
        a_ = a_/np.sqrt(np.sum(a_**2))
    L = np.sqrt(np.sum(a_**2))
    print("L is : "+str(L))'''

    tau = 1.5
    niter = 200
    a = PsiS(f0)
    for iter in range(niter):
        #gradient step
        a = np.add(a, tau * PsiS(Phi(f0 - Phi(Psi(a)))))
        #soft-threshold step
        a = SoftThresh(a, lmbd * tau)

        if iter % 20 == 0:
            print("Iteration : " + str(iter) + "\tCost : " + '%.4f' % ((np.sum(
                (f0 - Phi(Psi(a)))**2) / 2 + lmbd * np.sum(np.abs(a))) * 1e-4))

    return Psi(a)
コード例 #7
0
from nt_toolbox.perform_wavelet_transf import *

"""
    Load an image and solve the inverse problem
"""

f0 = load_image("DFB_artificial_dataset/im0_blurry.bmp")

plt.figure()
wavelets = 'sym5'
g,args = pywt.dwt2(f0, wavelets)
print(g)
print(np.shape(g))

plt.subplot(221)
imageplot(g)
plt.subplot(222)
imageplot(args[0])
plt.subplot(223)
imageplot(args[1])
plt.subplot(224)
imageplot(args[2])
 

print(f0)
plt.figure()
Jmin = 6
a = perform_wavelet_transf(f0, Jmin, +1);
plot_wavelet(a, Jmin)
plt.show()