def _find_source_patch(self, target_pixel):
target_patch = self._get_patch(target_pixel)
height, width = self.working_image.shape[:2]
patch_height, patch_width = self._patch_shape(target_patch)
best_match = None
best_match_difference = 0
lab_image = rgb2lab(self.working_image)
for y in range(height - patch_height + 1):
for x in range(width - patch_width + 1):
source_patch = [
[y, y + patch_height-1],
[x, x + patch_width-1]
]
if self._patch_data(self.working_mask, source_patch) \
.sum() != 0:
continue
difference = self._calc_patch_difference(
lab_image,
target_patch,
source_patch
)
if best_match is None or difference < best_match_difference:
best_match = source_patch
best_match_difference = difference
return best_match
评论列表
文章目录