From afb1510b929c29f4040fd7eb52f5ec0a0603eba7 Mon Sep 17 00:00:00 2001 From: Neeraj Gangwar Date: Tue, 25 Mar 2014 11:25:15 +0530 Subject: [PATCH] added testcases for greycomatrix for angles pi/4 and 3*pi/4 --- skimage/feature/tests/test_texture.py | 18 ++++++++++++++---- skimage/feature/texture.py | 12 +++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/skimage/feature/tests/test_texture.py b/skimage/feature/tests/test_texture.py index e4fb6acb..ad652afc 100644 --- a/skimage/feature/tests/test_texture.py +++ b/skimage/feature/tests/test_texture.py @@ -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, diff --git a/skimage/feature/texture.py b/skimage/feature/texture.py index f9bf6c9f..a4e69518 100644 --- a/skimage/feature/texture.py +++ b/skimage/feature/texture.py @@ -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) """