Ejemplo n.º 1
0
 def test_1_prob(self, im_shape, im_type, channel_wise):
     im = self.get_data(im_shape, im_type)
     intensity_range = [14, 14]
     t = RandKSpaceSpikeNoise(1.0, intensity_range, channel_wise)
     out = t(im)
     base_t = KSpaceSpikeNoise(t.sampled_locs, [14])
     out = out - base_t(im)
     assert_allclose(out, im * 0, type_test="tensor")
 def test_1_prob(self, im_shape, as_tensor_output, as_tensor_input,
                 channel_wise):
     im = self.get_data(im_shape, as_tensor_input)
     intensity_range = [14, 14]
     t = RandKSpaceSpikeNoise(1.0, intensity_range, channel_wise,
                              as_tensor_output)
     out = t(im)
     base_t = KSpaceSpikeNoise(t.sampled_locs, [14], as_tensor_output)
     out = out - base_t(im)
     np.testing.assert_allclose(out, im * 0)
 def test_1_prob(self, im_shape, im_type, channel_wise):
     im = self.get_data(im_shape, im_type)
     intensity_range = [14, 14]
     t = RandKSpaceSpikeNoise(1.0, intensity_range, channel_wise)
     out = t(im)
     base_t = KSpaceSpikeNoise(t.sampled_locs, [14])
     out = out - base_t(im)
     self.assertEqual(type(im), type(out))
     if isinstance(out, torch.Tensor):
         self.assertEqual(out.device, im.device)
         im, out = im.cpu(), out.cpu()
     np.testing.assert_allclose(out, im * 0)
Ejemplo n.º 4
0
    def test_same_result(self, im_shape, as_tensor_output, as_tensor_input):

        im = self.get_data(im_shape, as_tensor_input)
        loc = [0, int(im.shape[1] / 2), 0
               ] if len(im_shape) == 2 else [0, int(im.shape[1] / 2), 0, 0]
        k_intensity = 10
        t = KSpaceSpikeNoise(loc, k_intensity, as_tensor_output)

        out1 = t(deepcopy(im))
        out2 = t(deepcopy(im))

        np.testing.assert_allclose(out1, out2)
        self.assertIsInstance(out1,
                              torch.Tensor if as_tensor_output else np.ndarray)
Ejemplo n.º 5
0
    def test_highlighted_kspace_pixel(self, im_shape, as_tensor_output,
                                      as_tensor_input):

        im = self.get_data(im_shape, as_tensor_input)
        loc = [0, int(im.shape[1] / 2), 0
               ] if len(im_shape) == 2 else [0, int(im.shape[1] / 2), 0, 0]
        k_intensity = 10
        t = KSpaceSpikeNoise(loc, k_intensity, as_tensor_output)
        out = t(im)

        n_dims = len(im_shape)
        out_k = fftshift(fftn(out, axes=tuple(range(-n_dims, 0))),
                         axes=tuple(range(-n_dims, 0)))
        log_mag = np.log(np.absolute(out_k))
        np.testing.assert_allclose(k_intensity, log_mag[tuple(loc)], 1e-4)
Ejemplo n.º 6
0
    def test_same_result(self, im_shape, im_type, k_intensity):

        im = self.get_data(im_shape, im_type)
        loc = [0, int(im.shape[1] / 2), 0
               ] if len(im_shape) == 2 else [0, int(im.shape[1] / 2), 0, 0]
        t = KSpaceSpikeNoise(loc, k_intensity)

        out1 = t(deepcopy(im))
        out2 = t(deepcopy(im))

        if isinstance(out1, torch.Tensor):
            out1 = out1.cpu()
            out2 = out2.cpu()

        np.testing.assert_allclose(out1, out2)
Ejemplo n.º 7
0
    def test_highlighted_kspace_pixel(self, im_shape, as_tensor_input,
                                      k_intensity):

        im = self.get_data(im_shape, as_tensor_input)
        loc = [0, int(im.shape[1] / 2), 0
               ] if len(im_shape) == 2 else [0, int(im.shape[1] / 2), 0, 0]
        t = KSpaceSpikeNoise(loc, k_intensity)
        out = t(im)

        if isinstance(out, torch.Tensor):
            out = out.cpu()

        if k_intensity is not None:
            n_dims = len(im_shape)
            out_k = fftshift(fftn(out, axes=tuple(range(-n_dims, 0))),
                             axes=tuple(range(-n_dims, 0)))
            log_mag = np.log(np.absolute(out_k))
            np.testing.assert_allclose(k_intensity, log_mag[tuple(loc)], 1e-4)