From ed34d9f014cf6c92b51a20a657e4d6cda9190fcd Mon Sep 17 00:00:00 2001 From: walter Date: Wed, 15 Jun 2016 12:57:55 +0200 Subject: [PATCH] added a test for different data types --- skimage/feature/_texture.pyx | 5 +++-- skimage/feature/tests/test_texture.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/skimage/feature/_texture.pyx b/skimage/feature/_texture.pyx index ff77e0a7..fb4189c8 100644 --- a/skimage/feature/_texture.pyx +++ b/skimage/feature/_texture.pyx @@ -7,7 +7,7 @@ cimport numpy as cnp from libc.math cimport sin, cos, abs from .._shared.interpolation cimport bilinear_interpolation, round from .._shared.transform cimport integrate - +import cython cdef extern from "numpy/npy_math.h": double NAN "NPY_NAN" @@ -21,7 +21,8 @@ ctypedef fused any_int: cnp.int16_t cnp.int32_t cnp.int64_t - + + def _glcm_loop(any_int[:, ::1] image, double[:] distances, double[:] angles, Py_ssize_t levels, cnp.uint32_t[:, :, :, ::1] out): diff --git a/skimage/feature/tests/test_texture.py b/skimage/feature/tests/test_texture.py index ae54a6bb..4b88667a 100644 --- a/skimage/feature/tests/test_texture.py +++ b/skimage/feature/tests/test_texture.py @@ -15,6 +15,7 @@ class TestGLCM(): [0, 2, 2, 2], [2, 2, 3, 3]], dtype=np.uint8) + @test_parallel() def test_output_angles(self): result = greycomatrix(self.image, [1], [0, np.pi / 4, np.pi / 2, 3 * np.pi / 4], 4) @@ -50,6 +51,20 @@ class TestGLCM(): [0, 0, 2, 0]], dtype=np.uint32) np.testing.assert_array_equal(result[:, :, 0, 0], expected) + def test_image_data_types(self): + for dtype in [np.uint16, np.uint32, np.uint64, np.int16, np.int32, np.int64]: + img = self.image.astype(dtype) + result = greycomatrix(img, [1], [np.pi / 2], 4, + symmetric=True) + assert result.shape == (4, 4, 1, 1) + expected = np.array([[6, 0, 2, 0], + [0, 4, 2, 0], + [2, 2, 2, 2], + [0, 0, 2, 0]], dtype=np.uint32) + np.testing.assert_array_equal(result[:, :, 0, 0], expected) + + return + def test_output_distance(self): im = np.array([[0, 0, 0, 0], [1, 0, 0, 1],