コード例 #1
0
    def fuse(self, kernel_size):
        """Function which fuses each level of the pyramid using appropriate fusion operators
        the output is one pyramid containing fused levels"""
        log = logging.getLogger(".".join([__name__, self.__class__.__name__]))
        log.addFilter(logconfig.ThreadContextFilter())

        base_level_fused = self.get_fused_base(kernel_size)
        depth = self.collection[0].get_depth()
        fused = Pyramid(0,depth)
        fused.add_lower_resolution_level(base_level_fused)
        layers = len(self.collection)
        region_kernel = self.get_region_kernel()
        parameters = []
        for level in range(depth - 2, -1, -1):
            sh = self.collection[0].get_level(level).get_array().shape
            laplacians = np.zeros((layers, sh[0], sh [1]), dtype=np.float64)
            for layer in range(0, layers):
                new_level = self.collection[layer].get_level(level).get_array()
                laplacians[layer] = new_level
            param = (laplacians, region_kernel,level)
            parameters.append(param)
        pool = Pool()
        results = pool.map_async(fused_laplacian, parameters)
        bunch = results.get()
        pool.close()
        pool.join()

        fused.add_bunch_of_levels(bunch)

        fused.sort_levels()
        return fused
コード例 #2
0
 def test_collapse_returns_an_array_of_the_same_size_as_the_bottom_level(
         self):
     pyr = Pyramid(12, 3)
     level_0 = PyramidLevel(
         np.array([[10, 10, 10], [2, 2, 2], [4, 4, 4]], dtype=np.float64),
         2, 2)
     level_1 = PyramidLevel(np.array([[2, 2], [3, 3]], dtype=np.float64), 2,
                            2)
     level_2 = PyramidLevel(np.array([0], dtype=np.float64), 1, 1)
     pyr.add_lower_resolution_level(level_1)
     pyr.add_lower_resolution_level(level_0)
     pyr.add_lower_resolution_level(level_2)
     pyr.sort_levels()
     result = pyr.collapse()
     self.assertEqual(result.shape, level_0.get_array().shape)
コード例 #3
0
 def test_sort_levels_sorts_levels_according_to_size_larger_first(self):
     pyr = Pyramid(12, 3)
     level_0 = PyramidLevel(
         np.array([[10, 10, 10], [2, 2, 2], [4, 4, 4]], dtype=np.float64),
         2, 2)
     level_1 = PyramidLevel(np.array([[2, 2], [3, 3]], dtype=np.float64), 2,
                            2)
     level_2 = PyramidLevel(np.array([0], dtype=np.float64), 1, 1)
     pyr.add_lower_resolution_level(level_1)
     pyr.add_lower_resolution_level(level_0)
     pyr.add_lower_resolution_level(level_2)
     self.assertEqual(
         pyr.get_level(0).get_array().shape,
         level_1.get_array().shape)
     pyr.sort_levels()
     self.assertEqual(
         pyr.get_level(0).get_array().shape,
         level_0.get_array().shape)