在对图像噪点进行处理时,skimage的morphology提供了remove_small_objects的方法,这个方法可以去掉小于指定面积的噪点,但有些情况下我们需要去掉等于指定面积的噪点。
from skimage.measure import label as label_function
def remove_specified_objects(label, specified_area):
print('spcified_area',min_area)
label = label_function(label)
#把label变成一维数据后,统计里面不同连通区域像素个数
component_sizes = np.bincount(label.ravel())
print('component_sizes',component_sizes)
too_small = component_sizes == specified_area
print('too_small',too_small)
too_small_mask = too_small[label_test1[i,:,:]]
print('too_small_mask',too_small_mask)
#要移除的连通区域赋值为0
label[too_small_mask] = 0
程序中print结果如下图所示
print输出.png
网友评论