back.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:color-extractor 作者: algolia 项目源码 文件源码
def _global(self, img):
        h, w = img.shape[:2]
        mask = np.zeros((h, w), dtype=np.bool)
        max_distance = self._settings['max_distance']

        if self._settings['use_lab']:
            img = skc.rgb2lab(img)

        # Compute euclidean distance of each corner against all other pixels.
        corners = [(0, 0), (-1, 0), (0, -1), (-1, -1)]
        for color in (img[i, j] for i, j in corners):
            norm = np.sqrt(np.sum(np.square(img - color), 2))
            # Add to the mask pixels close to one of the corners.
            mask |= norm < max_distance

        return mask
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号