Simplify Image.color() and make in return ints instead of floats.
This commit is contained in:
parent
af351617d8
commit
dac3475579
1 changed files with 2 additions and 3 deletions
|
|
@ -18,7 +18,6 @@ import itertools
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy.stats.mstats import mode
|
|
||||||
from skimage.io import imread, imsave
|
from skimage.io import imread, imsave
|
||||||
|
|
||||||
from .utils import cached_property, pairwise
|
from .utils import cached_property, pairwise
|
||||||
|
|
@ -170,8 +169,8 @@ class Image(object):
|
||||||
return None
|
return None
|
||||||
mask3 = np.dstack([~self.bitmap] * 3)
|
mask3 = np.dstack([~self.bitmap] * 3)
|
||||||
colors = np.ma.MaskedArray(self.data, mask3).reshape(-1, 3)
|
colors = np.ma.MaskedArray(self.data, mask3).reshape(-1, 3)
|
||||||
modes, counts = mode(colors)
|
r, g, b = colors.mean(axis=0)
|
||||||
return tuple(modes[0])
|
return int(r), int(g), int(b)
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
"""Serialize the image as some hashable object."""
|
"""Serialize the image as some hashable object."""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue