mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-01 03:09:01 +08:00
ENH: Fix dtype conversion before hsv2rgb and rgb2hsv.
This commit is contained in:
@@ -103,7 +103,7 @@ def convert_colorspace(arr, fromspace, tospace):
|
||||
return todict[tospace](fromdict[fromspace](arr))
|
||||
|
||||
|
||||
def _prepare_colorarray(arr, dtype=np.float32):
|
||||
def _prepare_colorarray(arr):
|
||||
"""Check the shape of the array, and give it the requested type."""
|
||||
arr = np.asanyarray(arr)
|
||||
|
||||
@@ -111,7 +111,7 @@ def _prepare_colorarray(arr, dtype=np.float32):
|
||||
msg = "the input array must be have a shape == (.,.,3))"
|
||||
raise ValueError(msg)
|
||||
|
||||
return arr.astype(dtype)
|
||||
return dtype.img_as_float(arr)
|
||||
|
||||
|
||||
def rgb2hsv(rgb):
|
||||
@@ -303,7 +303,6 @@ def _convert(matrix, arr):
|
||||
out : ndarray, dtype=float
|
||||
The converted array.
|
||||
"""
|
||||
arr = dtype.img_as_float(arr)
|
||||
arr = _prepare_colorarray(arr)
|
||||
arr = np.swapaxes(arr, 0, 2)
|
||||
oldshape = arr.shape
|
||||
|
||||
@@ -44,7 +44,7 @@ class TestColorconv(TestCase):
|
||||
|
||||
# RGB to HSV
|
||||
def test_rgb2hsv_conversion(self):
|
||||
rgb = self.img_rgb.astype("float32")[::16, ::16]
|
||||
rgb = img_as_float(self.img_rgb)[::16, ::16]
|
||||
hsv = rgb2hsv(rgb).reshape(-1, 3)
|
||||
# ground truth from colorsys
|
||||
gt = np.array([colorsys.rgb_to_hsv(pt[0], pt[1], pt[2])
|
||||
|
||||
Reference in New Issue
Block a user