I have an image with edges looks like this:
(我有一个带有边缘的图像,看起来像这样:)
And I'm using this two methods to fix the edges:
(我正在使用这两种方法来修复边缘:)
def get_colors(pil_image, limit=4):
pil_image = np.array(pil_image)
image_colors = {}
for row in pil_image:
for pxl in row:
pxl = tuple(pxl)
if not image_colors.get(pxl):
image_colors[pxl] = 1
else:
image_colors[pxl] += 1
sorted_image_colors = sorted(image_colors, key=image_colors.get, reverse=True)
return sorted_image_colors[:limit]
def remove_anti_aliasing(colors, img_ndarr):
colors = np.array(colors).astype(np.int32)
img_ndarr = img_ndarr.astype(np.int32)
distances = np.argmin(np.array([np.sqrt(np.sum((color - img_ndarr) ** 2, axis=2)) for color in colors]), axis=0)
return colors[distances].astype(np.uint8)
And the result looks like this:
(结果看起来像这样:)
The edges still looks like the first but now the color is limited to 4.
(边缘仍然看起来像第一个,但现在颜色限制为4。)
I want to achieve something like this where there's only 2 colors on the edges:
(我想要实现这样的功能,其中边缘只有两种颜色:)
How can I do that?
(我怎样才能做到这一点?)
ask by conquistador translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…