示例#1
0
 def test_sensitivity_extraction_2D(self):
     """ This test ensures that the output of the non cartesian kspace
     extraction is same a that of mimicked cartesian extraction in 2D
     """
     _mask = np.ones((self.N, self.N))
     _samples = convert_mask_to_locations(_mask)
     fourier_op = NFFT(samples=_samples, shape=(self.N, self.N))
     Img = (np.random.randn(self.num_channel, self.N, self.N) +
            1j * np.random.randn(self.num_channel, self.N, self.N))
     F_img = np.asarray(
         [fourier_op.op(Img[i]) for i in np.arange(self.num_channel)])
     Smaps_gridding, SOS_Smaps = get_Smaps(k_space=F_img,
                                           img_shape=(self.N, self.N),
                                           samples=_samples,
                                           thresh=(0.4, 0.4),
                                           mode='gridding',
                                           min_samples=(-0.5, -0.5),
                                           max_samples=(0.5, 0.5),
                                           n_cpu=1)
     Smaps_NFFT, SOS_Smaps = get_Smaps(k_space=F_img,
                                       img_shape=(self.N, self.N),
                                       thresh=(0.4, 0.4),
                                       samples=_samples,
                                       min_samples=(-0.5, -0.5),
                                       max_samples=(0.5, 0.5),
                                       mode='NFFT')
     np.testing.assert_allclose(Smaps_gridding, Smaps_NFFT)
示例#2
0
 def test_extract_k_space_center_3D(self):
     """ This test ensures that the output of the non cartesian kspace
     extraction is same a that of mimicked cartesian extraction in 3D
     """
     _mask = np.ones((self.N, self.N, self.Nz))
     _samples = convert_mask_to_locations(_mask)
     Img = (np.random.randn(self.num_channel, self.N, self.N, self.Nz) +
            1j * np.random.randn(self.num_channel, self.N, self.N, self.Nz))
     Nby2_percent = self.N * self.percent / 2
     Nzby2_percent = self.Nz * self.percent / 2
     low = int(self.N / 2 - Nby2_percent)
     high = int(self.N / 2 + Nby2_percent + 1)
     lowz = int(self.Nz / 2 - Nzby2_percent)
     highz = int(self.Nz / 2 + Nzby2_percent + 1)
     center_Img = Img[:, low:high, low:high, lowz:highz]
     thresh = self.percent * 0.5
     data_thresholded, samples_thresholded = \
         extract_k_space_center_and_locations(
             data_values=np.reshape(Img, (self.num_channel,
                                          self.N * self.N * self.Nz)),
             samples_locations=_samples,
             thr=(thresh, thresh, thresh),
             img_shape=(self.N, self.N, self.Nz))
     np.testing.assert_allclose(center_Img.reshape(data_thresholded.shape),
                                data_thresholded)
    def test_sampling_converters(self):
        """Test the adjoint operator for the 2D non-Cartesian Fourier transform
        """
        for i in range(self.max_iter):
            print("Process test convert mask to samples test '{0}'...", i)
            Nx = numpy.random.randint(8, 512)
            Ny = numpy.random.randint(8, 512)
            mask = numpy.random.randint(2, size=(Nx, Ny))
            samples = convert_mask_to_locations(mask)
            recovered_mask = convert_locations_to_mask(samples, (Nx, Ny))
            self.assertEqual(mask.all(), recovered_mask.all())
            mismatch = 0. + (numpy.mean(numpy.allclose(mask, recovered_mask)))
            print("      mismatch = ", mismatch)
        print(" Test convert mask to samples and it's adjoint passes for",
              " the 2D cases")

        def test_sampling_converters_3D(self):
            """Test the adjoint operator for the 3D non-Cartesian Fourier
            transform
            """
            for i in range(self.max_iter):
                print("Process test convert mask to samples test '{0}'...", i)
                Nx = numpy.random.randint(8, 512)
                Ny = numpy.random.randint(8, 512)
                Nz = numpy.random.randint(8, 512)
                mask = numpy.random.randint(2, size=(Nx, Ny, Nz))
                samples = convert_mask_to_locations(mask)
                recovered_mask = convert_locations_to_mask(
                    samples, (Nx, Ny, Nz))
                self.assertEqual(mask.all(), recovered_mask.all())
                mismatch = 0. + (numpy.mean(
                    numpy.allclose(mask, recovered_mask)))
                print("      mismatch = ", mismatch)
            print(" Test convert mask to samples and it's adjoint passes for",
                  " the 3D cases")
示例#4
0
 def test_NFFT_3D(self):
     """Test the adjoint operator for the 3D non-Cartesian Fourier transform
     """
     for i in range(self.max_iter):
         _mask = numpy.random.randint(2, size=(self.N, self.N, self.N))
         _samples = convert_mask_to_locations(_mask)
         print("Process NFFT test in 3D '{0}'...", i)
         fourier_op_dir = NFFT(samples=_samples,
                               shape=(self.N, self.N, self.N))
         fourier_op_adj = NFFT(samples=_samples,
                               shape=(self.N, self.N, self.N))
         Img = numpy.random.randn(self.N, self.N, self.N) + \
             1j * numpy.random.randn(self.N, self.N, self.N)
         f = numpy.random.randn(_samples.shape[0], 1) + \
             1j * numpy.random.randn(_samples.shape[0], 1)
         f_p = fourier_op_dir.op(Img)
         I_p = fourier_op_adj.adj_op(f)
         x_d = numpy.dot(Img.flatten(), numpy.conj(I_p).flatten())
         x_ad = numpy.dot(f_p.flatten(), numpy.conj(f).flatten())
         self.assertTrue(numpy.isclose(x_d, x_ad, rtol=1e-10))
         mismatch = (1. - numpy.mean(
             numpy.isclose(x_d, x_ad,
                           rtol=1e-10)))
         print("      mismatch = ", mismatch)
     print(" NFFT in 3D adjoint test passes")
 def test_FFT2(self):
     """Test the adjoint operator for the 2D non-Cartesian Fourier transform
     """
     for i in range(self.max_iter):
         _mask = numpy.random.randint(2, size=(self.N, self.N))
         _samples = convert_mask_to_locations(_mask)
         print("Process FFT2 test '{0}'...", i)
         fourier_op_dir = FFT2(samples=_samples, shape=(self.N, self.N))
         fourier_op_adj = FFT2(samples=_samples, shape=(self.N, self.N))
         Img = (numpy.random.randn(self.N, self.N) +
                1j * numpy.random.randn(self.N, self.N))
         f = (numpy.random.randn(self.N, self.N) +
              1j * numpy.random.randn(self.N, self.N))
         f_p = fourier_op_dir.op(Img)
         I_p = fourier_op_adj.adj_op(f)
         x_d = numpy.vdot(Img, I_p)
         x_ad = numpy.vdot(f_p, f)
         numpy.testing.assert_allclose(x_d, x_ad, rtol=1e-10)
     print(" FFT2 adjoint test passes")
示例#6
0
 def test_extract_k_space_center_2D(self):
     """ Ensure that the extracted k-space center is right"""
     _mask = np.ones((self.N, self.N))
     _samples = convert_mask_to_locations(_mask)
     Img = (np.random.randn(self.num_channel, self.N, self.N) +
            1j * np.random.randn(self.num_channel, self.N, self.N))
     Nby2_percent = self.N * self.percent / 2
     low = int(self.N / 2 - Nby2_percent)
     high = int(self.N / 2 + Nby2_percent + 1)
     center_Img = Img[:, low:high, low:high]
     thresh = self.percent * 0.5
     data_thresholded, samples_thresholded = \
         extract_k_space_center_and_locations(
             data_values=np.reshape(Img, (self.num_channel,
                                          self.N * self.N)),
             samples_locations=_samples,
             thr=(thresh, thresh),
             img_shape=(self.N, self.N))
     np.testing.assert_allclose(center_Img.reshape(data_thresholded.shape),
                                data_thresholded)