diff --git a/skimage/io/_io.py b/skimage/io/_io.py index 0e50d5f9..ee01e405 100644 --- a/skimage/io/_io.py +++ b/skimage/io/_io.py @@ -157,7 +157,7 @@ def imshow(arr, plugin=None, **plugin_args): def imshow_collection(ic, plugin=None, **plugin_args): - """Display an image. + """Display a collection of images. Parameters ---------- diff --git a/skimage/io/_plugins/matplotlib_plugin.py b/skimage/io/_plugins/matplotlib_plugin.py index 3bd152c8..f54ac74b 100644 --- a/skimage/io/_plugins/matplotlib_plugin.py +++ b/skimage/io/_plugins/matplotlib_plugin.py @@ -171,7 +171,7 @@ def imshow_collection(ic, *args, **kwargs): """ fig, axes = plt.subplots(1, len(ic)) for n, image in enumerate(ic): - kwargs['axis'] = axes[n] + kwargs['ax'] = axes[n] imshow(image, *args, **kwargs) diff --git a/skimage/novice/__init__.py b/skimage/novice/__init__.py index 02da082b..ed46f6ad 100644 --- a/skimage/novice/__init__.py +++ b/skimage/novice/__init__.py @@ -56,9 +56,9 @@ Changing `size` resizes the picture. >>> picture.size = (45, 30) -We can preview the changes we made to the picture with our earlier command: +We can preview the changes we made to the picture with the ``compare`` command: ->>> picture.show() # doctest: +SKIP +>>> picture.compare() # doctest: +SKIP You can iterate over pixels, which have RGB values between 0 and 255, and know their location in the picture. @@ -88,6 +88,13 @@ True >>> picture.modified False +An image can also be restored to its original state after modification: + +>>> picture[0:20, 0:20] = (0, 0, 0) +>>> picture.compare() # doctest: +SKIP +>>> picture.reset() +>>> picture.compare() # doctest: +SKIP + """ from ._novice import Picture, open, colors, color_dict diff --git a/skimage/novice/_novice.py b/skimage/novice/_novice.py index 83d064c0..13c6f04b 100644 --- a/skimage/novice/_novice.py +++ b/skimage/novice/_novice.py @@ -7,6 +7,7 @@ from .. import io, img_as_ubyte from ..transform import resize from ..color import color_dict from ..io.util import file_or_url_context, is_url +from ..io.collection import ImageCollection import six from six.moves.urllib import request @@ -305,6 +306,7 @@ class Picture(object): def array(self, array): self._array = array self._xy_array = array_to_xy_origin(array) + self._array_backup = self._array.copy() @property def xy_array(self): @@ -329,6 +331,12 @@ class Picture(object): self._path = os.path.abspath(path) self._format = imghdr.what(path) + def reset(self): + """Reset image to its original state, removing modifications. + + """ + self.array = self._array_backup + @property def path(self): """The path to the picture.""" @@ -388,6 +396,13 @@ class Picture(object): io.imshow(self.array) io.show() + def compare(self): + """Compare the image to its unmodified version.""" + images = [self._array_backup, self.array] + ic = ImageCollection([0, 1], load_func=lambda x: images[x]) + io.imshow_collection(images) + io.show() + def _makepixel(self, x, y): """Create a Pixel object for a given x, y location.""" rgb = self.xy_array[x, y] diff --git a/skimage/novice/tests/test_novice.py b/skimage/novice/tests/test_novice.py index 70483c4e..ed49fb29 100644 --- a/skimage/novice/tests/test_novice.py +++ b/skimage/novice/tests/test_novice.py @@ -135,8 +135,18 @@ def test_modified_on_set_pixel(): assert pic.modified +def test_reset(): + pic = novice.Picture(SMALL_IMAGE_PATH) + v = pic[0, 0] + pic[0, 0] = (1, 1, 1) + pic.reset() + assert_equal(pic[0, 0], v) + + def test_update_on_save(): pic = novice.Picture(array=np.zeros((3, 3, 3))) + pic[0, 0] = (255, 255, 255) # prevent attempting to save low-contrast image + with all_warnings(): # precision loss pic.size = (6, 6) assert pic.modified