示例#1
0
 def test_run_length(self):
     matrix = np.array([[99, -59, 0, 7, 0, 0, 0,
                         0], [0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
                        [12, -2, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0]])
     rl = codec.run_length_coding(transform.zigzag(matrix))
     expected = [{
         'zeros': 0,
         'value': 99,
         'bits': 7
     }, {
         'zeros': 1,
         'value': -59,
         'bits': 6
     }, {
         'zeros': 6,
         'value': 7,
         'bits': 3
     }, {
         'zeros': 4,
         'value': 12,
         'bits': 4
     }, {
         'zeros': 1,
         'value': -2,
         'bits': 2
     }, {
         'zeros': 0,
         'value': 0,
         'bits': 0
     }]
     self.assertEqual([codec.RunLength.from_dict(e) for e in expected], rl)
示例#2
0
 def test_run_length_trivial(self):
     matrix = np.array([[1, 2], [3, 4]])
     rl = codec.run_length_coding(transform.zigzag(matrix)[1:])
     self.assertEqual(rl, [
         codec.RunLength(3, 0),
         codec.RunLength(2, 0),
         codec.RunLength(4, 0)
     ])
示例#3
0
 def test_zigzag(self):
     matrix = np.array([
         [1, 2, 3],
         [4, 5, 6],
         [7, 8, 9]
     ])
     d = trans.zigzag(matrix)
     self.assertTrue(np.array_equiv([
         1, 4, 2, 3, 5, 7, 8, 6, 9
     ], d))
示例#4
0
 def test_pull_subbands(self):
     expected = [
         np.array(range(4)).reshape((2, 2)),
         np.array(range(4, 8)).reshape((2, 2)),
         np.array(range(8, 12)).reshape((2, 2)),
         np.array(range(12, 16)).reshape((2, 2)),
         np.array(range(16, 32)).reshape((4, 4)),
         np.array(range(32, 48)).reshape((4, 4)),
         np.array(range(48, 64)).reshape((4, 4))
     ]
     data = np.array(utils.flatten([transform.zigzag(m) for m in expected]))
     shapes = [(2, 2), (4, 4)]
     out = codec.wavelet_decode_pull_subbands(data, shapes)
     self.assertEqual(len(expected), len(out))
     z = zip(expected, out)
     for e in z:
         self.assertTrue(np.array_equal(e[0], e[1]))
示例#5
0
 def collapse_subbands(k, v):
     out = [transform.zigzag(l) for l in v]
     out = utils.flatten(out)
     return out
示例#6
0
 def test_zero_block_reconstruct(self):
     matrix = np.array([[0, 0, 11, 0], [0, 0, 0, 0]])
     lin = transform.zigzag(matrix)
     out = codec.run_length_coding(lin)
     invert = codec.decode_run_length(out, 8)
     self.assertEqual(lin, invert)
示例#7
0
 def test_zero_block_rle(self):
     matrix = np.array([[0, 0, 11, 0], [0, 0, 0, 0]])
     lin = transform.zigzag(matrix)
     out = codec.run_length_coding(lin)
     self.assertEqual(out, [codec.RunLength(11, 3), codec.RunLength(0, 0)])
示例#8
0
 def test_zigzag_inverse(self):
     matrix = np.random.randint(0, 256, (17, 19))
     ziggy = trans.zigzag(matrix)
     imat = trans.izigzag(ziggy, matrix.shape)
     self.assertTrue(np.array_equiv(matrix, imat))