mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-16 11:21:25 +08:00
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:
@@ -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))
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user