From d2e04848453696acb68ddfea57ab455b6c8cc9a6 Mon Sep 17 00:00:00 2001 From: wilsaj Date: Fri, 20 Jul 2012 15:19:22 -0500 Subject: [PATCH] add html repr method for Image class --- skimage/io/_io.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/skimage/io/_io.py b/skimage/io/_io.py index 85e5c005..3e5bb670 100644 --- a/skimage/io/_io.py +++ b/skimage/io/_io.py @@ -1,10 +1,17 @@ __all__ = ['imread', 'imread_collection', 'imsave', 'imshow', 'show', 'push', 'pop'] +import base64 + from skimage.io._plugins import call as call_plugin from skimage.color import rgb2grey import numpy as np +try: + import cStringIO as StringIO +except ImportError: + import StringIO + # Shared image queue _image_stack = [] @@ -49,6 +56,12 @@ class Image(np.ndarray): object_state[2] = (object_state[2], subclass_state) return tuple(object_state) + def _repr_html_(self): + str_buffer = StringIO.StringIO() + imsave(str_buffer, self, format_str='png') + base64_str = base64.b64encode(str_buffer.getvalue()) + return '' % base64_str + def __setstate__(self, state): nd_state, subclass_state = state np.ndarray.__setstate__(self, nd_state)