From d9213beddef3293e387eecd89dd35dcb9d1005db Mon Sep 17 00:00:00 2001 From: David Koeller Date: Sun, 12 Jul 2015 11:07:21 -0500 Subject: [PATCH 1/2] Fix notebook display bug for novice module io.Image was previously removed, but the novice Picture still depended on it. Now moved the relevant functionality back into the Picture class. --- skimage/novice/_novice.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/skimage/novice/_novice.py b/skimage/novice/_novice.py index 80bc9649..77583146 100644 --- a/skimage/novice/_novice.py +++ b/skimage/novice/_novice.py @@ -384,9 +384,6 @@ class Picture(object): def height(self, value): self.size = (self.width, value) - def _repr_png_(self): - return io.Image(self._rescale(self.array))._repr_png_() - def show(self): """Display the image.""" io.imshow(self._rescale(self.array)) @@ -498,6 +495,19 @@ class Picture(object): def __repr__(self): return "Picture({0} x {1})".format(*self.size) + def _repr_png_(self): + return self._repr_image_format('png') + + def _repr_jpeg_(self): + return self._repr_image_format('jpeg') + + def _repr_image_format(self, format_str): + str_buffer = six.BytesIO() + io.imsave(str_buffer, self.array, format_str=format_str) + return_str = str_buffer.getvalue() + str_buffer.close() + return return_str + if __name__ == '__main__': import doctest From d4d3eaa1f19494862b3986bef822a6e101163339 Mon Sep 17 00:00:00 2001 From: David Koeller Date: Sun, 12 Jul 2015 11:47:07 -0500 Subject: [PATCH 2/2] Remove Picture.scale and Picture._rescale from novice module The scale and rescale function was never used in the novice module. These functions are extraneous in a novice code, and have no purpose there. Also updated tests. --- skimage/novice/_novice.py | 12 ++---------- skimage/novice/tests/test_novice.py | 1 - 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/skimage/novice/_novice.py b/skimage/novice/_novice.py index 77583146..83d064c0 100644 --- a/skimage/novice/_novice.py +++ b/skimage/novice/_novice.py @@ -249,7 +249,6 @@ class Picture(object): def __init__(self, path=None, array=None, xy_array=None): self._modified = False - self.scale = 1 self._path = None self._format = None @@ -325,7 +324,7 @@ class Picture(object): path : str Path (with file extension) where the picture is saved. """ - io.imsave(path, self._rescale(self.array)) + io.imsave(path, self.array) self._modified = False self._path = os.path.abspath(path) self._format = imghdr.what(path) @@ -386,7 +385,7 @@ class Picture(object): def show(self): """Display the image.""" - io.imshow(self._rescale(self.array)) + io.imshow(self.array) io.show() def _makepixel(self, x, y): @@ -394,13 +393,6 @@ class Picture(object): rgb = self.xy_array[x, y] return Pixel(self, self.array, x, y, rgb) - def _rescale(self, array): - """Rescale image according to scale factor.""" - if self.scale == 1: - return array - new_size = (self.height * self.scale, self.width * self.scale) - return img_as_ubyte(resize(array, new_size, order=0)) - def _get_channel(self, channel): """Return a specific dimension out of the raw image data slice.""" return self._array[:, :, channel] diff --git a/skimage/novice/tests/test_novice.py b/skimage/novice/tests/test_novice.py index 36f4a537..70483c4e 100644 --- a/skimage/novice/tests/test_novice.py +++ b/skimage/novice/tests/test_novice.py @@ -32,7 +32,6 @@ def test_pic_info(): assert_equal(pic.width, 451) assert_equal(pic.height, 300) assert not pic.modified - assert_equal(pic.scale, 1) def test_pixel_iteration():