tests for image types added

This commit is contained in:
walter
2016-06-16 10:33:11 +02:00
parent ed34d9f014
commit 6c47bd49dd
2 changed files with 23 additions and 8 deletions
+14
View File
@@ -51,6 +51,20 @@ class TestGLCM():
[0, 0, 2, 0]], dtype=np.uint32)
np.testing.assert_array_equal(result[:, :, 0, 0], expected)
def test_error_raise_float(self):
for dtype in [np.float, np.double, np.float16, np.float32, np.float64]:
np.testing.assert_raises(ValueError, greycomatrix, self.image.astype(dtype), [1], [np.pi], 4)
def test_error_raise_int_types(self):
for dtype in [np.int16, np.int32, np.int64, np.uint16, np.uint32, np.uint64]:
np.testing.assert_raises(ValueError, greycomatrix, self.image.astype(dtype), [1], [np.pi])
def test_error_raise_negative(self):
np.testing.assert_raises(ValueError, greycomatrix, self.image.astype(np.int16) - 1, [1], [np.pi], 4)
def test_error_raise_levels_smaller_max(self):
np.testing.assert_raises(ValueError, greycomatrix, self.image - 1, [1], [np.pi], 3)
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)
+9 -8
View File
@@ -102,7 +102,6 @@ def greycomatrix(image, distances, angles, levels=None, symmetric=False,
assert_nD(angles, 1, 'angles')
image = np.ascontiguousarray(image)
assert image.min() >= 0
image_max = image.max()
@@ -110,17 +109,19 @@ def greycomatrix(image, distances, angles, levels=None, symmetric=False,
raise ValueError("Float images are not supported by greycomatrix. "
"The image needs to be cast to an unsigned integer type.")
# for 16 bit images (or larger), levels must be set.
if image.dtype != np.uint8:
if levels is None:
raise ValueError("The levels argument is required for data types other than uint8. "
"The resulting matrix will be at least levels ** 2 in size.")
# for image type > 8bit, levels must be set.
if image.dtype not in (np.uint8, np.int8) and levels is None:
raise ValueError("The levels argument is required for data types other than uint8. "
"The resulting matrix will be at least levels ** 2 in size.")
if image.dtype in (np.int8, np.int16, np.int32, np.int64) and np.any(image < 0):
raise ValueError("Negative valued images are not supported.")
if levels is None:
levels = 256
assert image_max < levels, "The image maximum needs to be smaller than `levels`."
if image_max >= levels:
raise ValueError("The image maximum needs to be smaller than `levels`.")
distances = np.ascontiguousarray(distances, dtype=np.float64)
angles = np.ascontiguousarray(angles, dtype=np.float64)