From 2c635989d2d6f8264193e93cf3d446d8c4a578d5 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 30 Jan 2015 19:41:10 -0600 Subject: [PATCH 1/2] Force novice.Picture.from_size to return a uint8 image Force Picure.from_size to return a uint8 image Remove img_as_ubyte --- skimage/novice/_novice.py | 1 + skimage/novice/tests/test_novice.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/skimage/novice/_novice.py b/skimage/novice/_novice.py index cac72ee2..28df15d4 100644 --- a/skimage/novice/_novice.py +++ b/skimage/novice/_novice.py @@ -282,6 +282,7 @@ class Picture(object): color = color_dict[color] rgb_size = tuple(size) + (len(color),) array = np.ones(rgb_size, dtype=np.uint8) * color + array = array.astype(np.uint8) # Force RGBA internally (use max alpha) if array.shape[-1] == 3: diff --git a/skimage/novice/tests/test_novice.py b/skimage/novice/tests/test_novice.py index e2aafef0..36f4a537 100644 --- a/skimage/novice/tests/test_novice.py +++ b/skimage/novice/tests/test_novice.py @@ -86,6 +86,8 @@ def test_pixel_rgb(): pixel.rgb = np.arange(4) assert_equal(pixel.rgb, np.arange(3)) + assert pic.array.dtype == np.uint8 + def test_pixel_rgba(): pic = novice.Picture.from_size((3, 3), color=(10, 10, 10)) From 0859b3662e345b45da52186dc0ba832dcf0653d1 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 30 Jan 2015 21:01:45 -0600 Subject: [PATCH 2/2] Avoid creating an int64 array --- skimage/novice/_novice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/novice/_novice.py b/skimage/novice/_novice.py index 28df15d4..24c2ff0e 100644 --- a/skimage/novice/_novice.py +++ b/skimage/novice/_novice.py @@ -281,8 +281,8 @@ class Picture(object): if isinstance(color, six.string_types): color = color_dict[color] rgb_size = tuple(size) + (len(color),) + color = np.array(color, dtype=np.uint8) array = np.ones(rgb_size, dtype=np.uint8) * color - array = array.astype(np.uint8) # Force RGBA internally (use max alpha) if array.shape[-1] == 3: