FIX: Testing for ubyte and float images. Input dtypes are converted beforehand.

This commit is contained in:
spotter
2013-03-07 00:14:06 +01:00
parent 0a6b72bfe4
commit 7439fe96e8
2 changed files with 9 additions and 11 deletions
+2 -1
View File
@@ -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)
+7 -10
View File
@@ -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