【发布时间】:2016-09-14 16:19:05
【问题描述】:
【问题讨论】:
标签: python numpy scipy noise-reduction
【问题讨论】:
标签: python numpy scipy noise-reduction
如果无法根据阈值确定信号中的噪声(即所有红点都具有相同的值或只是一个 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 文档中的示例,该示例将样本块中的对角接触像素分组。
【讨论】: