
这是卫星的分类图像。有人能告诉我如何去除这些单一像素的过滤器吗。记住,这是Geotiff格式的。我已经应用了侵蚀或扩张技术,但没有成功。
发布于 2021-07-13 08:27:05
我看到了一个类似的问题,但找不到。有一个很好的答案,我为自己重新做了。下面是一个名为particle_filter的方法,它将解决您的问题:
def particle_filter(image_, power):
nb_components, output, stats, centroids = cv2.connectedComponentsWithStats(image_, connectivity=8)
sizes = stats[1:, -1]
nb_components = nb_components - 1
min_size = power
img2 = np.zeros(output.shape, dtype=np.uint8)
for i in range(0, nb_components):
if sizes[i] >= min_size:
img_to_compare = threshold_gray_const(output, (i + 1, i + 1))
img2 = binary_or(img2, img_to_compare)
img2 = img2.astype(np.uint8)
return img2
def threshold_gray_const(image_, rang: tuple):
return cv2.inRange(image_, rang[0], rang[1])
def binary_or(image_1, image_2):
return cv2.bitwise_or(image_1, image_2)您所需要做的就是调用此函数,并将二进制图像作为第一个参数,将滤波功率作为第二个参数。
一点解释:整个方法--只是对图像上的对象进行迭代,如果一个对象的面积小于power,那么简单地删除它。
发布于 2021-07-13 08:12:50
我会尝试中值滤波器(cv2.medianBlur),它应该删除单个像素,但也可能有其他影响。您需要使用很少不同的设置来测试它,并决定它是否提供了可接受的结果。
中值滤波器的内核大小应该是奇数,因此中值用于奇数像素数(大小3为9,5为25,7为49等等),因此中值滤波器从不引入新值,因此,如果使用二进制图像作为输入,则会得到二进制图像作为输出。
https://stackoverflow.com/questions/68358462
复制相似问题