def forwardBackwardConvol(Niter,
                          x0,
                          H,
                          y,
                          nLevel,
                          Lambda,
                          k=3,
                          multiscale=False):
    Htilde = getHtilde(H)
    nu = getLipConst(H, Htilde)
    gamma = nu / 2
    gamma = 1
    #gamma = 1
    print("gamma = ", gamma)
    theta = 1
    x = cp.copy(x0)
    (c, w) = tp1.Starlet_Forward2D(x, J=nLevel)
    arrayLambdas = getDetectionLevels(y, k, nLevel)

    for i in range(Niter):
        print("iteration " + str(i + 1) + "/" + str(Niter))
        (gradC, gradW) = getGradConvol(c, w, H, Htilde, y, nLevel, h)
        wHalf = w - gamma * gradW
        c = c - gamma * gradC
        if (multiscale == False):
            w = w + theta * (softThrd(wHalf, gamma * Lambda) - w)
        else:
            w = w + theta * (softThrdMultiScale(wHalf, gamma * arrayLambdas) -
                             w)
        print("error = ", error(xStar, tp1.Starlet_Backward2D(c, w)))
    res = tp1.Starlet_Backward2D(c, w)
    return res
def forwardBackwardInpainting(Niter,
                              x0,
                              mask,
                              y,
                              nLevel,
                              Lambda,
                              k=3,
                              multiscale=False):
    nu = 1
    gamma = nu
    theta = 1.5
    xOld = cp.copy(x0)
    (c, w) = tp1.Starlet_Forward2D(x=xOld, J=nLevel)
    arrayLambdas = getDetectionLevels(y, k, nLevel)

    for i in range(Niter):
        print("iteration " + str(i + 1) + "/" + str(Niter))
        (gradC, gradW) = getGradInpainting(c, w, mask, y, nLevel)
        wHalf = w - gamma * gradW
        c = c - gamma * gradC
        if (multiscale == False):
            w = w + theta * (softThrd(wHalf, gamma * Lambda) - w)
        else:
            w = w + theta * (softThrdMultiScale(wHalf, gamma * arrayLambdas) -
                             w)
        print("error = ", error(xStar, tp1.Starlet_Backward2D(c, w)))
    res = tp1.Starlet_Backward2D(c, w)
    return res
def getGradf(c, w, mask, y, nLevel):
    x = tp1.Starlet_Backward2D(c, w)
    Fx = fft2(x, norm="ortho") - y
    res = mask * Fx
    res = ifft2(res, norm="ortho")
    res = np.real(res)
    cNew, wNew = tp1.Starlet_Forward2D(res, J=nLevel)
    return cNew, wNew
def Starlet_Backward2D_Multidim(cMultidim, wMultidim):
    (n, tailleIm, tailleIm, J) = wMultidim.shape
    SformatImage = np.zeros((n, tailleIm, tailleIm))
    for i in range(n):
        SformatImage[i, :, :] = tp1.Starlet_Backward2D(cMultidim[i],
                                                       wMultidim[i, :, :, :])
    SformatLigne = SformatImage.reshape((n, tailleIm**2))
    return SformatLigne
def FBS(Niter, x0, mask, y, noise, nLevel, Lambda, k=3, multiscale=False):
    nu = 1
    gamma = 1.9 / nu
    theta = 2 - gamma * nu / 2
    xOld = cp.copy(x0)
    (c, w) = tp1.Starlet_Forward2D(x=xOld, J=nLevel)
    arrayLambdas = to.getDetectionLevels(noise, k, nLevel)
    print(arrayLambdas)
    for i in range(Niter):
        if (i % 10 == 0):
            print("iteration " + str(i + 1) + "/" + str(Niter))
        (gradC, gradW) = getGradf(c, w, mask, y, nLevel)
        wHalf = w - gamma * gradW
        c = c - gamma * gradC
        if (multiscale == False):
            w = w + theta * (to.softThrd(wHalf, gamma * Lambda) - w)
        else:
            w = w + theta * (
                to.softThrdMultiScale(wHalf, gamma * arrayLambdas) - w)
        x = tp1.Starlet_Backward2D(c, w)
        print("error = ", to.error(x0, x))
    res = tp1.Starlet_Backward2D(c, w)
    return res
Ejemplo n.º 6
0
def getProxSynthesis(x,
                     gamma,
                     theta,
                     arrayLambdas=0,
                     nLevel=3,
                     multiscale=False):
    #print("array lambdas in function", arrayLambdas)
    (c, w) = tp1.Starlet_Forward2D(x, J=nLevel)
    if (multiscale == False):
        w = to.softThrd(w, gamma * Lambda)
    else:
        w = to.softThrdMultiScale(w, gamma * arrayLambdas)
    res = tp1.Starlet_Backward2D(c, w)
    return res
def reconstruction(y, nbLevel, k, prior):
    (c, w) = tp1.Starlet_Forward2D(x=y, J=nbLevel)
    for i in range(nbLevel):
        wi = w[:, :, i]
        gamma = k * getSigmaMAD(wi)
        if (prior == "softThrd"):
            sparseW = softThrd(wi, gamma)
        elif (prior == "hardThrd"):
            sparseW = hardThrd(wi, gamma)
        else:
            print("Error this prior is not implemented")
        w[:, :, i] = sparseW
        """plt.figure()
        plt.imshow(w, cmap='gray')
        plt.figure()
        plt.imshow(sparseW, cmap='gray')"""
    reconst = tp1.Starlet_Backward2D(c, w)
    return reconst
Ejemplo n.º 8
0
def prox_StarletEuclidean(X,kmad=3,W=None,J=2):

    import Starlet2D as st2

    m = np.shape(X)[0]
    Xout = dp(X)

    for q in range(m):

        c,w = st2.Starlet_Forward2D(X[q,:,:],h=[0.0625,0.25,0.375,0.25,0.0625],J=J,boption=3)

        for r in range(J):

            if W == None:
                w[:,:,r] = prox_soft(w[:,:,r],kmad*mad(w[:,:,r]))
            else:
                w[:,:,r] = prox_soft(w[:,:,r],W[:,:,r,q]) # W should depend on the observation

        Xout[q,:,:] = st2.Starlet_Backward2D(c,w)

    return Xout
def getGradInpainting(c, w, mask, y, nLevel):
    x = tp1.Starlet_Backward2D(c, w)
    res = mask * (x - y)
    (gradC, gradW) = tp1.Starlet_Forward2D(x=res, J=nLevel)
    return (gradC, gradW)
def getGradConvol(c, w, H, Htilde, y, nLevel, h):
    x = tp1.Starlet_Backward2D(c, w)
    gradx = convol(x, H) - y
    gradx = convol(gradx, Htilde)
    (gradC, gradW) = tp1.Starlet_Forward2D(gradx, J=nLevel)
    return (gradC, gradW)