def _hard_monochrome(self, sample):
"""
Return the monochrome colors corresponding to `sample`, if any.
A boolean is also returned, specifying whether or not the saturation is
sufficient for non monochrome colors.
"""
gray_proj = np.inner(sample, Name._GRAY_UNIT) * Name._GRAY_UNIT
gray_dist = norm(sample - gray_proj)
if gray_dist > 15:
return []
colors = []
luminance = np.sum(sample * Name._GRAY_COEFF)
if luminance > 45 and luminance < 170:
colors.append(self._settings['gray_name'])
if luminance <= 50:
colors.append(self._settings['black_name'])
if luminance >= 170:
colors.append(self._settings['white_name'])
return colors
# Normalized identity (BGR gray) vector.
评论列表
文章目录