From dac3475579824ca1ff0082d2cc72f2e85136cb6d Mon Sep 17 00:00:00 2001 From: Andrey Golovizin Date: Tue, 2 Sep 2014 14:33:39 +0200 Subject: [PATCH] Simplify Image.color() and make in return ints instead of floats. --- pixelocr/image.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pixelocr/image.py b/pixelocr/image.py index 57a9762..b380fe6 100644 --- a/pixelocr/image.py +++ b/pixelocr/image.py @@ -18,7 +18,6 @@ import itertools from io import BytesIO import numpy as np -from scipy.stats.mstats import mode from skimage.io import imread, imsave from .utils import cached_property, pairwise @@ -170,8 +169,8 @@ class Image(object): return None mask3 = np.dstack([~self.bitmap] * 3) colors = np.ma.MaskedArray(self.data, mask3).reshape(-1, 3) - modes, counts = mode(colors) - return tuple(modes[0]) + r, g, b = colors.mean(axis=0) + return int(r), int(g), int(b) def serialize(self): """Serialize the image as some hashable object."""