Beispiel #1
0
def wf(y, mask, iter, verbose=False):

    m = y.size
    n = mask.sum()

    mu_max = 0.2
    t0 = 330.

    y = y**2
    lambd2 = y.sum()

    x = np.random.rand(*y.shape)
    x[~mask] = np.zeros(m - n)
    x = x / np.linalg.norm(x, 2)
    for i in range(1000):
        x = tools.ifft2d(y * tools.fft2d(x))
        x[~mask] = np.zeros(m - n)
        x = x / np.linalg.norm(x, 2)
    x = x * np.sqrt(lambd2)

    for t in range(iter):
        mu = np.min([1 - np.exp(-t / t0), mu_max])
        f = tools.fft2d(x)
        x = x - mu * tools.ifft2d((f**2 - y) * f) / lambd2
        x[~mask] = np.zeros(m - n)
        x = np.real(x)
    res = np.real(x)
    return res
Beispiel #2
0
def oss(y, mask, beta=0.9, verbose=False):

    phase = np.random.rand(*y.shape) * 2 * np.pi
    x_prev = np.real(tools.ifft2d(y * np.exp(1j * phase)))
    sigma1 = np.linspace(y.shape[0], 1. / y.shape[0], 10)
    sigma2 = np.linspace(y.shape[1], 1. / y.shape[1], 10)

    filtercount = 10
    iter = 2000
    Rsize = y.shape[0]
    X = np.arange(1, iter + 1)
    FX = (filtercount + 1 - np.ceil(X * filtercount / iter)) * np.ceil(
        iter / (1 * filtercount))
    FX = ((FX - np.ceil(iter / filtercount)) *
          (2 * Rsize) / np.max(FX)) + (2 * Rsize / 10)

    for i in range(iter):

        if i == 0 or FX[i - 1] != FX[i]:
            sigma = (FX[i], FX[i])
            filter = tools.get_gauss2d(y.shape, sigma, normalize=False)
            filter = ifftshift(filter)

        Fx_curr = y * np.exp(1j * phase)
        x_curr = np.real(tools.ifft2d(Fx_curr))
        idx = (x_curr < 0) + (mask == False)
        x_curr[idx] = x_prev[idx] - beta * x_curr[idx]
        Fx_curr = tools.fft2d(x_curr)
        idx = (mask == False)
        x_curr[idx] = np.real(tools.ifft2d(Fx_curr * filter))[idx]
        Fx_curr = tools.fft2d(x_curr)
        phase = np.angle(Fx_curr)
        x_prev = x_curr.copy()

    return x_curr
Beispiel #3
0
 def prox(self, x, tau=1):
     # z = np.zeros(y.shape)
     # z[self.mask] = x.flatten()
     z = x
     zf = tools.fft2d(z)
     mag = 1 / (self.alpha + tau) * (self.alpha * self.y + tau * np.abs(zf))
     res = mag * np.exp(1j * np.angle(zf))
     res = np.real(tools.ifft2d(res))
     # return res[self.mask].reshape(x.shape)
     return res
Beispiel #4
0
def hio(y, mask, iter, beta=0.9, verbose=False):

    phase = np.random.rand(*y.shape) * 2 * np.pi
    x_prev = np.real(tools.ifft2d(y * np.exp(1j * phase)))

    for i in range(iter):

        if verbose:
            print('Iteration #{:d} '.format(i + 1), end='')

        Fx_curr = y * np.exp(1j * phase)
        x_curr = np.real(tools.ifft2d(Fx_curr))
        idx = ((1 + beta) * x_curr < x_prev) + (mask == False)
        # idx = (x_curr < 0) + (mask == False)
        x_curr[idx] = x_prev[idx] - beta * x_curr[idx]
        Fx_curr = tools.fft2d(x_curr)
        phase = np.angle(Fx_curr)
        x_prev = x_curr.copy()

        # residual = np.power(y - np.abs(new_f), 2).mean()

    return x_curr
 def prox(self, x, tau=1):
     xf = tools.fft2d(x)
     mag = 1 / (self.alpha + tau) * (self.alpha * self.y + tau * np.abs(xf))
     res = mag * np.exp(1j*np.angle(xf))
     res = np.real(tools.ifft2d(res))
     return res
 def grad(self, x):
     f = tools.fft2d(x)
     return self.alpha * np.real(tools.ifft2d(f - y * f / np.abs(f)))
        res = np.real(tools.ifft2d(res))
        return res

y = scipy.io.loadmat('simulated_circle.mat')
y = y['simulated_circle']
y = ifftshift(y) * np.sqrt(y.size)
# y = y * np.sqrt(y.size)
# y = scipy.io.loadmat('15mm_circle_082621.mat')
# y = ifftshift(y) / 10.
# y = scipy.io.loadmat('LUX_082621.mat')
# y = y['For_PR']
# y = y['Pi_spec_sim_abs_PR']
# y = ifftshift(y) * 3.
y = y * args.scale

v00 = np.real(tools.ifft2d(y))

# print(tools.ifft2d(y))
#  * np.sqrt(y.size)
mask = np.ones(y.shape, dtype=bool) * False
midpt = (mask.shape[0]//2, mask.shape[1]//2)
mask[midpt[0]-supdim[0]//2:midpt[0]+supdim[0]-supdim[0]//2,
     midpt[1]-supdim[1]//2:midpt[1]+supdim[1]-supdim[1]//2] = np.ones(supdim, dtype=bool) * True

v0 = algo.hio(y, mask, args.hioiter)
v0[~mask] = np.zeros(y.size - mask.sum())

fidelity = FourMagMSE(y, 50**2 / (args.lambd**2), mask)
denoiser = dnsr.DnCNN('DnCNN/weights/dncnn50_17.pth')
optimizer = optim.PnPADMMHIO(fidelity, denoiser)
optimizer.init(v0, np.zeros(y.shape))