【问题标题】:Removing the single pixels from Geotiff bianary image [closed]从 Geotiff 二进制图像中删除单个像素 [关闭]
【发布时间】:2021-09-22 06:36:04
【问题描述】:

这是卫星的分类图像。谁能告诉我如何去除这些单个像素的过滤器。请记住,这是 Geotiff 格式。我已经应用了腐蚀或膨胀技术,但没有成功。

【问题讨论】:

  • 请附上您尝试过的代码以及运行时收到的任何错误消息。您可能还想阅读How to Ask a Good Question 上的指南。

标签: python image cv2


【解决方案1】:

我在 SO 上看到了类似的问题,但找不到。我为自己重新制作了一个很好的答案。所以这里有一个名为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)

您需要做的就是调用此函数并将您的二值图像作为第一个参数,filter power 作为第二个参数。
一点解释:Whole method - 只是简单地迭代图像上的对象,如果一个对象的面积小于power,那么它只是删除。

【讨论】:

  • 它正在工作,非常感谢......唯一的问题是,当我使用“nb_components, output, stats, centroids = cv2.connectedComponentsWithStats(image_, connectivity=8)”时,它给出了一个错误的过程以退出代码 139 结束(被信号 11:SIGSEGV 中断)。有什么解决办法??
【解决方案2】:

我会尝试 Median Filter (cv2.medianBlur),它应该可以去除单个像素,但也可能有其他效果。您需要使用几个不同的设置对其进行测试,并确定它是否确实为您提供了可接受的结果。

中值滤波器的内核大小应该是奇数,因此中值用于奇数个像素(9 表示大小 3,25 表示大小 5,49 表示大小 7 等等),因此 中值滤波器 从不引入新值,因此如果你使用二值图像作为输入,你将得到二值图像作为输出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多