Esempio n. 1
0
 def _naive_reduce_width(src, num_seams, energy_mode):
     for _ in range(num_seams):
         gray = src if src.ndim == 2 else carve._rgb2gray(src)
         if energy_mode == 'backward':
             seam = carve._get_backward_seam(carve._get_energy(gray))
         else:
             seam = carve._get_forward_seam(gray, None)
         src = carve._remove_seam(src, seam)
     return src
Esempio n. 2
0
 def test_remove_seam(self):
     for src in (self.gray, self.rgb):
         for _ in range(self.delta):
             gray = src if src.ndim == 2 else carve._rgb2gray(src)
             energy = carve._get_energy(gray)
             seam = carve._get_backward_seam(energy)
             dst = carve._remove_seam(src, seam)
             ans_dst = self._naive_remove_seam(src, seam)
             assert (dst == ans_dst).all()
             src = dst
Esempio n. 3
0
 def test_get_backward_seam(self):
     energy = carve._get_energy(self.gray)
     seam = carve._get_backward_seam(energy)
     ans_seam = self._naive_get_backward_seam(energy)
     assert (seam == ans_seam).all()
Esempio n. 4
0
 def test_get_backward_seam(self):
     energy = carve._get_energy(self.gray)
     seam, cost = carve._get_backward_seam(energy)
     ans_seam, ans_cost = self._naive_get_backward_seam(energy)
     assert (seam == ans_seam).all()
     assert math.isclose(cost, ans_cost)