Skip to content

Commit

Permalink
Merge pull request scikit-image#3146 from hmaarrfk/bugfix_separate_st…
Browse files Browse the repository at this point in the history
…ains_log10

Bugfix separate stains log10
  • Loading branch information
emmanuelle authored Jun 6, 2018
2 parents aab8ca7 + e8426ed commit b58a488
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions doc/release/release_dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Improvements
API Changes
-----------

- ``colorconv.separate_stains`` and ``colorconv.combine_stains`` now uses
base10 instead of the natural logarithm as discussed in issue #2995.



Bugfixes
Expand Down
4 changes: 2 additions & 2 deletions skimage/color/colorconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ def separate_stains(rgb, conv_matrix):
"""
rgb = dtype.img_as_float(rgb, force_copy=True)
rgb += 2
stains = np.reshape(-np.log(rgb), (-1, 3)) @ conv_matrix
stains = np.reshape(-np.log10(rgb), (-1, 3)) @ conv_matrix
return np.reshape(stains, rgb.shape)


Expand Down Expand Up @@ -1474,7 +1474,7 @@ def combine_stains(stains, conv_matrix):

stains = dtype.img_as_float(stains)
logrgb2 = -np.reshape(stains, (-1, 3)) @ conv_matrix
rgb2 = np.exp(logrgb2)
rgb2 = np.power(10, logrgb2)
return rescale_intensity(np.reshape(rgb2 - 2, stains.shape),
in_range=(-1, 1))

Expand Down
7 changes: 4 additions & 3 deletions skimage/color/tests/test_colorconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,11 @@ def test_hdx_rgb_roundtrip(self):
img_rgb = self.img_rgb
conv = combine_stains(separate_stains(img_rgb, hdx_from_rgb),
rgb_from_hdx)
assert_equal(img_as_ubyte(conv), img_rgb)
with expected_warnings('precision loss'):
assert_equal(img_as_ubyte(conv), img_rgb)

# RGB<->HDX roundtrip with ubyte image
def test_hdx_rgb_roundtrip(self):
# RGB<->HDX roundtrip with float image
def test_hdx_rgb_roundtrip_float(self):
from skimage.color.colorconv import hdx_from_rgb, rgb_from_hdx
img_rgb = img_as_float(self.img_rgb)
conv = combine_stains(separate_stains(img_rgb, hdx_from_rgb),
Expand Down

0 comments on commit b58a488

Please sign in to comment.