FIX: img_as_ubyte function threw ValueError due to floating point errors in hed2rgb function.

Clipping the output of the hed2rgb function between 0 and 1 seems to correct
the bug without affecting the conversion quality.
This commit is contained in:
spotter
2013-03-08 12:58:22 +01:00
parent 7439fe96e8
commit 7c371e1662
2 changed files with 5 additions and 3 deletions
+3 -1
View File
@@ -807,7 +807,9 @@ def hed2rgb(hed):
>>> ihc_hed = rgb2hed(ihc)
>>> ihc_rgb = hed2rgb(ihc_hed)
"""
from ..exposure import rescale_intensity
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)
return rescale_intensity(np.reshape(rgb1 - 1, hed.shape), in_range=(0, 1))
+2 -2
View File
@@ -16,7 +16,7 @@ import os.path
import numpy as np
from numpy.testing import *
from skimage import img_as_float
from skimage import img_as_float, img_as_ubyte
from skimage.io import imread
from skimage.color import (
rgb2hsv, hsv2rgb,
@@ -125,7 +125,7 @@ class TestColorconv(TestCase):
# RGB<->HED roundtrip with ubyte image
def test_hed_rgb_roundtrip(self):
img_rgb = self.img_rgb
assert_array_almost_equal(hed2rgb(rgb2hed(img_rgb)), img_as_float(img_rgb))
assert_equal(img_as_ubyte(hed2rgb(rgb2hed(img_rgb))), img_rgb)
# RGB<->HED roundtrip with float image
def test_hed_rgb_float_roundtrip(self):