Merge pull request #955 from neerajgangwar/add-test-greycomatrix

Add test cases for greycomatrix
This commit is contained in:
Stefan van der Walt
2014-04-07 14:02:18 +02:00
2 changed files with 25 additions and 5 deletions
+14 -4
View File
@@ -11,18 +11,28 @@ class TestGLCM():
[2, 2, 3, 3]], dtype=np.uint8)
def test_output_angles(self):
result = greycomatrix(self.image, [1], [0, np.pi / 2], 4)
assert result.shape == (4, 4, 1, 2)
result = greycomatrix(self.image, [1], [0, np.pi / 4, np.pi / 2, 3 * np.pi / 4], 4)
assert result.shape == (4, 4, 1, 4)
expected1 = np.array([[2, 2, 1, 0],
[0, 2, 0, 0],
[0, 0, 3, 1],
[0, 0, 0, 1]], dtype=np.uint32)
np.testing.assert_array_equal(result[:, :, 0, 0], expected1)
expected2 = np.array([[3, 0, 2, 0],
expected2 = np.array([[1, 1, 3, 0],
[0, 1, 1, 0],
[0, 0, 0, 2],
[0, 0, 0, 0]], dtype=np.uint32)
np.testing.assert_array_equal(result[:, :, 0, 1], expected2)
expected3 = np.array([[3, 0, 2, 0],
[0, 2, 2, 0],
[0, 0, 1, 2],
[0, 0, 0, 0]], dtype=np.uint32)
np.testing.assert_array_equal(result[:, :, 0, 1], expected2)
np.testing.assert_array_equal(result[:, :, 0, 2], expected3)
expected4 = np.array([[2, 0, 0, 0],
[1, 1, 2, 0],
[0, 0, 2, 1],
[0, 0, 0, 0]], dtype=np.uint32)
np.testing.assert_array_equal(result[:, :, 0, 3], expected4)
def test_output_symmetric_1(self):
result = greycomatrix(self.image, [1], [np.pi / 2], 4,
+11 -1
View File
@@ -66,17 +66,27 @@ def greycomatrix(image, distances, angles, levels=256, symmetric=False,
... [0, 0, 1, 1],
... [0, 2, 2, 2],
... [2, 2, 3, 3]], dtype=np.uint8)
>>> result = greycomatrix(image, [1], [0, np.pi/2], levels=4)
>>> result = greycomatrix(image, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4], levels=4)
>>> result[:, :, 0, 0]
array([[2, 2, 1, 0],
[0, 2, 0, 0],
[0, 0, 3, 1],
[0, 0, 0, 1]], dtype=uint32)
>>> result[:, :, 0, 1]
array([[1, 1, 3, 0],
[0, 1, 1, 0],
[0, 0, 0, 2],
[0, 0, 0, 0]], dtype=uint32)
>>> result[:, :, 0, 2]
array([[3, 0, 2, 0],
[0, 2, 2, 0],
[0, 0, 1, 2],
[0, 0, 0, 0]], dtype=uint32)
>>> result[:, :, 0, 3]
array([[2, 0, 0, 0],
[1, 1, 2, 0],
[0, 0, 2, 1],
[0, 0, 0, 0]], dtype=uint32)
"""