Added docs, tests for downsample() in skimage.transform._warps

This commit is contained in:
Ankit Agrawal
2013-07-04 17:31:27 +08:00
parent 329cf37ca2
commit 7282f561d4
5 changed files with 103 additions and 62 deletions
+28 -1
View File
@@ -1,4 +1,4 @@
from numpy.testing import assert_array_almost_equal, run_module_suite
from numpy.testing import assert_array_almost_equal, run_module_suite, assert_array_equal
import numpy as np
from scipy.ndimage import map_coordinates
@@ -193,6 +193,33 @@ def test_warp_coords_example():
coords = warp_coords(tform, (30, 30, 3))
map_coordinates(image[:, :, 0], coords[:2])
def test_downsample_sum():
"""Verifying downsampling of an array with expected result in sum mode"""
image1 = np.arange(4*6).reshape(4, 6)
out1 = tf.downsample(image1, (2, 3))
expected1 = np.array([[ 24, 42],
[ 96, 114]])
assert_array_equal(expected1, out1)
image2 = np.arange(5*8).reshape(5, 8)
out2 = tf.downsample(image2, (3, 3))
expected2 = np.array([[ 81, 108, 87],
[174, 192, 138]])
assert_array_equal(expected2, out2)
def test_downsample_mean():
"""Verifying downsampling of an array with expected result in mean mode"""
image1 = np.arange(4*6).reshape(4, 6)
out1 = tf.downsample(image1, (2, 3), 'mean')
expected1 = np.array([[ 4., 7.],
[ 16., 19.]])
assert_array_equal(expected1, out1)
image2 = np.arange(5*8).reshape(5, 8)
out2 = tf.downsample(image2, (4, 5), 'mean')
expected2 = np.array([[ 14. , 10.8],
[ 8.5, 5.7]])
assert_array_equal(expected2, out2)
if __name__ == "__main__":
run_module_suite()