Пример #1
0
 def test_wavelet_transformations(self):
     """ Test all the registered transformations.
     """
     for image in self.images:
         print("Process test with image '{0}'...".format(
             image.metadata["path"]))
         for nb_scale in self.nb_scales:
             print("- Number of scales: {0}".format(nb_scale))
             for transform in self.transforms:
                 print("    Transform: {0}".format(transform))
                 transform = transform(nb_scale=nb_scale, verbose=0)
                 self.assertFalse(transform.use_wrapping)
                 transform.info
                 transform.data = image
                 transform.analysis()
                 # transform.show()
                 recim = transform.synthesis()
                 # recim.show()
                 mismatch = (1. - numpy.mean(
                     numpy.isclose(
                         recim.data, image.data, atol=1e-8, rtol=1e-5)))
                 print("      mismatch = ", mismatch)
                 print("      analysis = ",
                       [band.shape for band in transform.analysis_data],
                       len(transform.analysis_data))
                 print("      bands = ", transform.nb_band_per_scale)
                 print("      synthesis = ", recim.shape)
Пример #2
0
 def test_speed(self):
     """ Test the bindings time advantages.
     """
     # With/without bindings
     for strategy, name in ((True, "Without"), (False, "With")):
         tic = time.time()
         transform = pysap.load_transform(
             "LinearWaveletTransformATrousAlgorithm")
         transform = transform(nb_scale=4, verbose=0)
         transform.use_wrapping = strategy
         transform.data = self.images[0]
         for i in range(self.nb_iter):
             transform.analysis()
             recim = transform.synthesis()
         toc = time.time()
         print("[result] {0} bindings execution time: {1}.".format(
             name, toc - tic))
Пример #3
0
    def test_accessors(self):
        """ Test all the accessors.
        """
        # With/without bindings
        for strategy, name in ((True, "without"), (False, "with")):

            # Test 3-bands undecimated transform
            nb_scale = 4
            print("[info] Test {0} bindings.".format(name))
            transform = pysap.load_transform(
                "NonOrthogonalUndecimatedTransform")
            transform = transform(nb_scale=nb_scale, verbose=0)
            transform.use_wrapping = strategy
            transform.data = self.images[0]
            transform.analysis()

            # Get with scale index only
            for scale in range(nb_scale - 1):
                band_data = transform[scale]
                self.assertEqual(len(band_data), 3)
                for band_array in band_data:
                    self.assertEqual(band_array.shape, (512, 512))
            band_array = transform[nb_scale - 1]
            self.assertEqual(band_array.shape, (512, 512))

            # Get with scale and band
            self.assertEqual(transform[0, 0].shape, (512, 512))

            # Get with scale and band as slice
            band_data = transform[2, 1:3:1]
            self.assertEqual(len(band_data), 2)
            for band_array in band_data:
                self.assertEqual(band_array.shape, (512, 512))

            # Get with scale as slice and band
            band_data = transform[1:3, 0]
            self.assertEqual(len(band_data), 2)
            for band_array in band_data:
                self.assertEqual(band_array.shape, (512, 512))

            # Modify a band on the fly
            band_array = transform[0, 0]
            band_array[:, :] = 10
            self.assertTrue(numpy.allclose(transform[0, 0], band_array))
Пример #4
0
    def test_wavelet_transformations(self):
        """ Test all the registered transformations.
        """
        for image_i in self.images:
            print("Process test with image '{0}'...".format(
                image_i.metadata["path"]))
            for nb_scale in self.nb_scales:
                print("- Number of scales: {0}".format(nb_scale))
                for transform in self.transforms:
                    print("    Transform: {0}".format(transform))
                    if transform.__family__ == "isap-2d":
                        transform = transform(nb_scale=nb_scale,
                                              verbose=0,
                                              padding_mode="symmetric")
                    else:
                        transform = transform(nb_scale=nb_scale, verbose=0)

                    image = numpy.copy(image_i)

                    if transform.data_dim == 3:
                        image = image[64:192, 64:192]
                        image = numpy.tile(image, (image.shape[0], 1, 1))
                        transform.data = image
                    else:
                        transform.data = image

                    self.assertFalse(transform.use_wrapping)
                    transform.info
                    transform.analysis()
                    # transform.show()
                    recim = transform.synthesis()
                    # recim.show()
                    mismatch = (1. - numpy.mean(
                        numpy.isclose(recim.data, image, atol=1e-8,
                                      rtol=1e-5)))
                    print("      mismatch = ", mismatch)
                    print("      analysis = ",
                          [band.shape for band in transform.analysis_data],
                          len(transform.analysis_data))
                    print("      bands = ", transform.nb_band_per_scale)
                    print("      synthesis = ", recim.shape)