【问题标题】:Noise removal in spatial data空间数据中的噪声去除
【发布时间】:2016-09-14 16:19:05
【问题描述】:

我有一个数组,其中包含两个不同的值来表征此图像:

我想将线性趋势保持为红色并去除“噪音”(单个红点)。有没有好的方法来做到这一点?

【问题讨论】:

    标签: python numpy scipy noise-reduction


    【解决方案1】:

    如果无法根据阈值确定信号中的噪声(即所有红点都具有相同的值或只是一个 1/0 标志),则可以采用相对简单但易于实施的方法看看根据团块的大小去除噪音。

    看看scipy's label。这将为您提供一个数组,其中每个单独的“团块”都有一个单独的数字。然后只是删除那些小于某个阈值像素数的特征(下面的n_thresh)。

    >>> from scipy.ndimage.measurements import label
    >>> import numpy as np
    >>> n_thresh = 1
    >>> a = np.array([[0,0,1,1,0,0],[0,0,0,1,0,0],
                      [1,1,0,0,1,0],[0,0,0,1,0,0],
                      [1,1,0,0,1,0],[0,0,1,1,0,0]])
    >>> a
    array([[0, 0, 1, 1, 0, 0],
           [0, 0, 0, 1, 0, 0],
           [1, 1, 0, 0, 1, 0],
           [0, 0, 0, 1, 0, 0],
           [1, 1, 0, 0, 1, 0],
           [0, 0, 1, 1, 0, 0]])
    >>> labeled_array, num_features = label(a)
    >>> binc = np.bincount(labeled_array.ravel())
    >>> noise_idx = np.where(binc <= n_thresh)
    >>> shp = a.shape
    >>> mask = np.in1d(labeled_array, noise_idx).reshape(shp)
    >>> a[mask] = 0
    >>> a
    array([[0, 0, 1, 1, 0, 0],
           [0, 0, 0, 1, 0, 0],
           [1, 1, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0],
           [1, 1, 0, 0, 0, 0],
           [0, 0, 1, 1, 0, 0]])
    >>> a
    

    由于特征是对角的,您可能需要注意label 文档中的示例,该示例将样本块中的对角接触像素分组。

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 2022-10-04
      • 2017-12-30
      • 2012-12-28
      • 2012-11-14
      • 2017-07-05
      • 2017-08-27
      • 1970-01-01
      • 2023-04-05
      相关资源
      最近更新 更多