Ejemplo n.º 1
0
    def poisson_solve(self, func, ps, eps, symm, reflect):
        N = len(func)

        if reflect != 0:
            N = N * 2
            func = tf.concat([func, tf.image.flip_left_right(func)], axis=1)
            func = tf.concat([func, tf.image.flip_up_down(func)], axis=0)

        wx = 2 * np.pi * tf.range(0, N, 1, dtype=tf.float32) / N
        fx = 1 / (2 * np.pi * ps) * (wx - np.pi * (1 - N % 2 / N))
        [Fx, Fy] = tf.meshgrid(fx, fx)
        func_ft = signal.fftshift(signal.fft2d(tf.cast(func, tf.complex64)))

        Psi_ft = func_ft / tf.cast(
            (-4 * np.pi**2 * (Fx**2 + Fy**2 + eps)), tf.complex64)
        if (symm):
            # Psi_xy = np.fft.irfft2(signal.ifftshift(Psi_ft)[:,0:N//2+1])
            Psi_xy = signal.ifft2d(signal.ifftshift(Psi_ft))
        else:
            Psi_xy = signal.ifft2d(signal.ifftshift(Psi_ft))

        if reflect != 0:
            N = N // 2
            Psi_xy = Psi_xy[:N, :N]
        # print("Psi_ft: ", Psi_ft.shape, "Psi_xy: ", Psi_xy.shape)
        return Psi_xy
Ejemplo n.º 2
0
 def call(self, kspace, *args):
     axes = [tf.rank(kspace) - 2,
             tf.rank(kspace) - 1]  # axes have to be positive...
     dtype = tf.math.real(kspace).dtype
     scale = tf.math.sqrt(
         tf.cast(tf.math.reduce_prod(tf.shape(kspace)[-2:]), dtype))
     return dlmri_tutorial.complex_scale(
         fftshift(ifft2d(ifftshift(kspace, axes=axes)), axes=axes), scale)
Ejemplo n.º 3
0
    def propagate(self, Ein, lambd, Z, ps):  #, varargin):

        (m, n) = Ein.shape
        M = m
        N = n

        gpu_num = 0  # check gpu

        mask = 1

        # Initialize variables into CPU or GPU
        if (gpu_num == 0):
            if self.Eout is None:
                self.Eout = tf.Variable(1j * tf.zeros(
                    (m, n, len(Z)), dtype=tf.complex64))
            aveborder = tf.reduce_mean(
                tf.concat((Ein[0, :], Ein[m - 1, :], tf.transpose(
                    Ein[:, 0]), tf.transpose(Ein[:, n - 1])),
                          axis=0))
            #np.mean(cat(2,Ein(1,:),Ein(m,:),Ein(:,1)',Ein(:,n)'));
            H = tf.zeros((M, N, len(Z)))

        else:
            # reset(gpuDevice(1));
            raise NotImplementedError
            # lambd = gpuArray(lambd);
            # Z = gpuArray(Z);
            # ps = gpuArray(ps);
            # Eout = gpuArray.zeros(m,n,length(Z));
            # aveborder=gpuArray(mean(cat(2,Ein(1,:),Ein(m,:),Ein(:,1)',Ein(:,n)')));
            # if nargout>1
            #     H = gpuArray.zeros(M,N,length(Z));

        # Spatial Sampling
        [x, y] = tf.meshgrid(tf.range(-N / 2, (N / 2 - 1) + 1),
                             tf.range(-M / 2, (M / 2 - 1) + 1))

        fx = (x / (ps * M))  #frequency space width [1/m]
        fy = (y / (ps * N))  #frequency space height [1/m]
        fx2fy2 = fx**2 + fy**2

        # Padding value
        Ein_pad = Ein
        # Ein_pad = tf.ones((M,N), dtype = tf.complex64) * aveborder #pad by average border value to avoid sharp jumps
        # Ein_pad[(M-m)//2:(M+m)//2,(N-n)//2:(N+n)//2] = Ein # what is this?
        # Ein_pad = tf.pad(Ein, ((), ()), aveborder)

        # FFT of E0
        E0fft = signal.fftshift(signal.fft2d(Ein_pad))
        for z in range(len(Z)):
            H = tf.exp(-1j * np.pi * tf.cast(
                lambd * Z[z] * fx2fy2, tf.complex64))  #Fast Transfer Function
            Eout_pad = signal.ifft2d(signal.ifftshift(E0fft * H * mask))

            self.Eout[:, :, z].assign(Eout_pad[(M - m) // 2:(M + m) // 2,
                                               (N - n) // 2:(N + n) // 2])
            # Eout[:,:,z]=Eout_pad[(M-m)//2:(M+m)//2,(N-n)//2:(N+n)//2]

        # Gather variables from GPU if necessary
        if (gpu_num > 0):
            raise NotImplementedError
            # Eout=gather(Eout);
            # if nargout > 1:
            #     H=gather(H);

        return self.Eout  # H not returned?
Ejemplo n.º 4
0
 def Ft(x):
     return signal.ifftshift(signal.ifft2d(signal.fftshift(x)))