From 7439fe96e854db26915b47bbb631b2459b2d4ba4 Mon Sep 17 00:00:00 2001 From: spotter Date: Thu, 7 Mar 2013 00:14:06 +0100 Subject: [PATCH] FIX: Testing for ubyte and float images. Input dtypes are converted beforehand. --- skimage/color/colorconv.py | 3 ++- skimage/color/tests/test_colorconv.py | 17 +++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/skimage/color/colorconv.py b/skimage/color/colorconv.py index 0ff4c722..8f44880c 100644 --- a/skimage/color/colorconv.py +++ b/skimage/color/colorconv.py @@ -769,7 +769,7 @@ def rgb2hed(rgb): >>> ihc = data.ihc() >>> ihc_hed = rgb2hed(ihc) """ - rgb = rgb.astype(float) + 1 + rgb = dtype.img_as_float(rgb) + 1 hed = np.dot(np.reshape(-np.log(rgb), (-1, 3)), hed_from_rgb) return np.reshape(hed, rgb.shape) @@ -807,6 +807,7 @@ def hed2rgb(hed): >>> ihc_hed = rgb2hed(ihc) >>> ihc_rgb = hed2rgb(ihc_hed) """ + hed = dtype.img_as_float(hed) logrgb1 = np.dot(-np.reshape(hed, (-1, 3)), rgb_from_hed) rgb1 = np.exp(logrgb1) return np.reshape(rgb1 - 1, hed.shape) diff --git a/skimage/color/tests/test_colorconv.py b/skimage/color/tests/test_colorconv.py index 7e76ded3..3171028d 100644 --- a/skimage/color/tests/test_colorconv.py +++ b/skimage/color/tests/test_colorconv.py @@ -122,17 +122,14 @@ class TestColorconv(TestCase): img_rgb = img_as_float(self.img_rgb) assert_array_almost_equal(xyz2rgb(rgb2xyz(img_rgb)), img_rgb) - # RGB<->HED roundtrip + # RGB<->HED roundtrip with ubyte image def test_hed_rgb_roundtrip(self): - img_rgb = np.array([[[97, 105, 152], - [217, 187, 225], - [117, 107, 168]], - [[217, 187, 225], - [176, 135, 83], - [234, 144, 205]], - [[97, 105, 152], - [117, 107, 168], - [217, 187, 225]]], dtype=np.uint8) + img_rgb = self.img_rgb + assert_array_almost_equal(hed2rgb(rgb2hed(img_rgb)), img_as_float(img_rgb)) + + # RGB<->HED roundtrip with float image + def test_hed_rgb_float_roundtrip(self): + img_rgb = img_as_float(self.img_rgb) assert_array_almost_equal(hed2rgb(rgb2hed(img_rgb)), img_rgb) # RGB to RGB CIE