|
| 1 | +__author__ = 'jrx' |
| 2 | + |
| 3 | + |
| 4 | +import numpy as np |
| 5 | + |
| 6 | +from numpy.testing import assert_array_equal |
| 7 | +from nose.tools import assert_greater, assert_equal |
| 8 | + |
| 9 | + |
| 10 | +from encoder.algorithms.xor_encoding import XorEncoding |
| 11 | + |
| 12 | + |
| 13 | +def test_capacity_monotonic(): |
| 14 | + shape = (640, 480, 3) |
| 15 | + |
| 16 | + base = XorEncoding(block_size=6, intensity=4) |
| 17 | + low_block = XorEncoding(block_size=5, intensity=4) |
| 18 | + high_intensity = XorEncoding(block_size=5, intensity=8) |
| 19 | + |
| 20 | + assert_greater(low_block.data_capacity(shape), base.data_capacity(shape)) |
| 21 | + assert_greater(high_intensity.data_capacity(shape), base.data_capacity(shape)) |
| 22 | + |
| 23 | + assert_equal(base.data_capacity(shape), 43192) |
| 24 | + assert_equal(low_block.data_capacity(shape), 71992) |
| 25 | + assert_equal(high_intensity.data_capacity(shape), 143992) |
| 26 | + |
| 27 | + |
| 28 | +def test_base(): |
| 29 | + image = np.random.randint(0, 256, (640, 480, 3)).astype(np.uint8) |
| 30 | + encoding = XorEncoding(block_size=6, intensity=4) |
| 31 | + max_size = encoding.data_capacity(image.shape) |
| 32 | + |
| 33 | + data = np.random.randint(0, 256, max_size).astype(np.uint8) |
| 34 | + |
| 35 | + encoded = encoding.encode(image, data) |
| 36 | + |
| 37 | + assert_equal(encoded.dtype, np.uint8) |
| 38 | + assert_equal(encoded.shape, image.shape) |
| 39 | + |
| 40 | + decoded = encoding.decode(encoded) |
| 41 | + |
| 42 | + assert_equal(decoded.dtype, np.uint8) |
| 43 | + assert_equal(decoded.shape, data.shape) |
| 44 | + |
| 45 | + assert_array_equal(data, decoded) |
| 46 | + |
| 47 | + |
| 48 | +def test_high_intensity(): |
| 49 | + image = np.random.randint(0, 256, (640, 480, 3)).astype(np.uint8) |
| 50 | + encoding = XorEncoding(block_size=6, intensity=8) |
| 51 | + max_size = encoding.data_capacity(image.shape) |
| 52 | + |
| 53 | + data = np.random.randint(0, 256, max_size).astype(np.uint8) |
| 54 | + |
| 55 | + encoded = encoding.encode(image, data) |
| 56 | + |
| 57 | + assert_equal(encoded.dtype, np.uint8) |
| 58 | + assert_equal(encoded.shape, image.shape) |
| 59 | + |
| 60 | + decoded = encoding.decode(encoded) |
| 61 | + |
| 62 | + assert_equal(decoded.dtype, np.uint8) |
| 63 | + assert_equal(decoded.shape, data.shape) |
| 64 | + |
| 65 | + assert_array_equal(data, decoded) |
| 66 | + |
| 67 | + |
| 68 | +def test_low_block(): |
| 69 | + image = np.random.randint(0, 256, (640, 480, 3)).astype(np.uint8) |
| 70 | + encoding = XorEncoding(block_size=1, intensity=1) |
| 71 | + max_size = encoding.data_capacity(image.shape) |
| 72 | + |
| 73 | + data = np.random.randint(0, 256, max_size).astype(np.uint8) |
| 74 | + |
| 75 | + encoded = encoding.encode(image, data) |
| 76 | + |
| 77 | + assert_equal(encoded.dtype, np.uint8) |
| 78 | + assert_equal(encoded.shape, image.shape) |
| 79 | + |
| 80 | + decoded = encoding.decode(encoded) |
| 81 | + |
| 82 | + assert_equal(decoded.dtype, np.uint8) |
| 83 | + assert_equal(decoded.shape, data.shape) |
| 84 | + |
| 85 | + assert_array_equal(data, decoded) |
| 86 | + |
| 87 | + |
0 commit comments