def equal_color(img: Image, color):
arr_img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
arr_img = cv2.resize(arr_img, (img.size[0] * 10, img.size[1] * 10))
boundaries = []
boundaries.append(([max(color[2] - 15, 0), max(color[1] - 15, 0), max(color[0] - 15, 0)],
[min(color[2] + 15, 255), min(color[1] + 15, 255), min(color[0] + 15, 255)]))
for (lower, upper) in boundaries:
lower = np.array(lower, dtype="uint8")
upper = np.array(upper, dtype="uint8")
# find the colors within the specified boundaries and apply
# the mask
mask = cv2.inRange(arr_img, lower, upper)
res = cv2.bitwise_and(arr_img, arr_img, mask=mask)
res = cv2.resize(res, (img.size[0], img.size[1]))
cv2_im = cv2.cvtColor(res, cv2.COLOR_BGR2RGB)
output_img = Image.fromarray(cv2_im)
return output_img
评论列表
文章目录