Exemple #1
0
    def test_real_input(self):
        reference_image = cp.array(camera())
        subpixel_shift = (-2.4, 1.32)
        shifted_image = fourier_shift(cp.asnumpy(cp.fft.fftn(reference_image)),
                                      subpixel_shift)
        shifted_image = cp.fft.ifftn(cp.array(shifted_image))

        # subpixel precision
        result, error, diffphase = register_translation_cu(
            reference_image, shifted_image, 100)
        assert_allclose(result[:2], -cp.array(subpixel_shift), atol=0.05)
Exemple #2
0
 def test_subpixel_precision(self):
     reference_image = cp.fft.fftn(cp.array(camera()))
     subpixel_shift = (-2.4, 1.32)
     reference_image_np = cp.asnumpy(reference_image)
     shifted_image = fourier_shift(reference_image_np, subpixel_shift)
     shifted_image = cp.array(shifted_image)
     # subpixel precision
     result, error, diffphase = register_translation_cu(reference_image,
                                                        shifted_image,
                                                        100,
                                                        space="fourier")
     assert_allclose(result[:2], -cp.array(subpixel_shift), atol=0.05)
Exemple #3
0
    def test_correlation(self):

        reference_image = cp.fft.fftn(cp.array(camera()))
        shift = (-7, 12)
        reference_image_np = cp.asnumpy(reference_image)
        shifted_image = fourier_shift(reference_image_np, shift)
        shifted_image = cp.array(shifted_image)
        # pixel precision
        result, error, diffphase = register_translation_cu(reference_image,
                                                           shifted_image,
                                                           space="fourier")
        assert_allclose(result[:2], -cp.array(shift))
Exemple #4
0
    def test_size_one_dimension_input(self):
        # take a strip of the input image
        reference_image = cp.fft.fftn(cp.array(camera())[:, 15]).reshape(
            (-1, 1))
        subpixel_shift = (-2.4, 4)

        shifted_image = fourier_shift(cp.asnumpy(reference_image),
                                      subpixel_shift)
        shifted_image = cp.array(shifted_image)
        # subpixel precision
        result, error, diffphase = register_translation_cu(reference_image,
                                                           shifted_image,
                                                           100,
                                                           space="fourier")
        assert_allclose(result[:2], -cp.array((-2.4, 0)), atol=0.05)
Exemple #5
0
 def test_3d_input(self):
     phantom = cp.array(img_as_float(binary_blobs(length=32, n_dim=3)))
     reference_image = cp.fft.fftn(phantom)
     shift = (-2., 1., 5.)
     shifted_image = fourier_shift(cp.asnumpy(reference_image), shift)
     shifted_image = cp.array(shifted_image)
     result, error, diffphase = register_translation_cu(reference_image,
                                                        shifted_image,
                                                        space="fourier")
     assert_allclose(result, -cp.array(shift), atol=0.05)
     # subpixel precision not available for 3-D data
     subpixel_shift = (-2.3, 1., 5.)
     shifted_image = fourier_shift(cp.asnumpy(reference_image),
                                   subpixel_shift)
     shifted_image = cp.array(shifted_image)
     result, error, diffphase = register_translation_cu(reference_image,
                                                        shifted_image,
                                                        space="fourier")
     assert_allclose(result, -cp.array(shift), atol=0.5)
     with self.assertRaises(NotImplementedError):
         register_translation_cu(reference_image,
                                 shifted_image,
                                 upsample_factor=100,
                                 space="fourier")
Exemple #6
0
    def test_wrong_input(self):
        # Dimensionality mismatch
        image = cp.ones((5, 5, 1))
        template = cp.ones((5, 5))
        with self.assertRaises(ValueError):
            register_translation_cu(template, image)

        # Greater than 2 dimensions does not support subpixel precision
        #   (TODO: should support 3D at some point.)
        image = cp.ones((5, 5, 5))
        template = cp.ones((5, 5, 5))
        with self.assertRaises(NotImplementedError):
            register_translation_cu(template, image, 2)

        # Size mismatch
        image = cp.ones((5, 5))
        template = cp.ones((4, 4))
        with self.assertRaises(ValueError):
            register_translation_cu(template, image)
Exemple #7
0
 def test_unknown_space_input(self):
     image = cp.ones((5, 5))
     with self.assertRaises(ValueError):
         register_translation_cu(image, image, space="frank")