Add docstrings.

This commit is contained in:
Andrey Golovizin 2014-08-08 13:08:18 +02:00
parent b934788bc0
commit c427d60030

View file

@ -45,15 +45,32 @@ class Image(object):
@cached_property
def bitmap(self):
"""Return a two-color version of the image.
0 = white (blank) pixel
1 = black (letter) pixel
"""
grayscale = rgb2gray(self._data)
return (grayscale < 1).astype('b')
@property
def key(self):
"""Return a byte string uniquely representing the image."""
return self.tostring()
def tostring(self):
"""Serialize the image as a string."""
height, width, *_ = self.shape
shape = '{}x{}'.format(height, width)
shape = '{}x{}'.format(height, width).encode('latin1')
bitmap = np.packbits(self.bitmap).tostring()
return shape.encode('latin1') + b':' + bitmap
return shape + b':' + bitmap
@classmethod
def fromstring(cls, data):
"""Deserialize an image from a string."""
# TODO
raise NotImplementedError
def unframe(self, width=2):
return self[width:-width,width:-width]