空间数据中的噪声去除

Noise removal in spatial data

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

我想保留红色的线性趋势并删除 "noise"(单个红点)。有没有好的方法来做到这一点?

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

看看scipy's label。这将为您提供一个数组,其中每个单独的 'clump' 都有一个单独的数字。然后就是删除那些小于某个阈值像素的特征(下面的 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 文档中的示例,该示例将样本块中的对角线像素分组。