[英]How can I transform an image to group colors?
Sorry if this has been asked before, but I couldn't find anything without having a more descriptive name of the transformation.抱歉,如果以前有人问过这个问题,但是如果没有更具描述性的转换名称,我找不到任何东西。
I would like to apply a transform on either a PIL image or an array of floats that represent a black and white image.我想对 PIL 图像或表示黑白图像的浮点数组应用变换。 Ideally the transform would alter the image like this (sorry, made in paint with a track pad):理想情况下,变换会像这样改变图像(对不起,用触控板涂漆):
I would consider it a bonus if it could preserve a black border around each color region, but that might be asking a lot depending on how the transform works.如果它可以在每个颜色区域周围保留一个黑色边框,我会认为它是一个奖励,但这可能会要求很多,具体取决于变换的工作方式。 Thanks in advance:)提前致谢:)
You can try morphological operation on the image:您可以尝试对图像进行形态学操作:
import cv2 as cv
import numpy as np
img = cv.imread('img.png',0)
kernel = np.ones((5,5),np.uint8)
# Opening is erosion followed by dilation. It is useful in removing noise.
opening = cv.morphologyEx(img, cv.MORPH_OPEN, kernel)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.