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
评论列表
文章目录