ENH: Fix dtype conversion before hsv2rgb and rgb2hsv.

This commit is contained in:
Stefan van der Walt
2012-02-08 18:27:25 -08:00
parent 5c9c8c1867
commit ec8f62ef5f
2 changed files with 3 additions and 4 deletions
+2 -3
View File
@@ -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
+1 -1
View File
@@ -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])