mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-08 09:51:14 +08:00
added a test for different data types
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user