Add docstrings.
This commit is contained in:
parent
b934788bc0
commit
c427d60030
1 changed files with 19 additions and 2 deletions
|
|
@ -45,15 +45,32 @@ class Image(object):
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def bitmap(self):
|
def bitmap(self):
|
||||||
|
"""Return a two-color version of the image.
|
||||||
|
|
||||||
|
0 = white (blank) pixel
|
||||||
|
1 = black (letter) pixel
|
||||||
|
"""
|
||||||
|
|
||||||
grayscale = rgb2gray(self._data)
|
grayscale = rgb2gray(self._data)
|
||||||
return (grayscale < 1).astype('b')
|
return (grayscale < 1).astype('b')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def key(self):
|
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
|
height, width, *_ = self.shape
|
||||||
shape = '{}x{}'.format(height, width)
|
shape = '{}x{}'.format(height, width).encode('latin1')
|
||||||
bitmap = np.packbits(self.bitmap).tostring()
|
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):
|
def unframe(self, width=2):
|
||||||
return self[width:-width,width:-width]
|
return self[width:-width,width:-width]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue