首页 > 解决方案 > 如何去除图像中的噪声以设置连通分量中的像素值?

问题描述

我在输入图像上应用了 ostu 阈值。在此之后我应用了连接分量分析。我想去除小于 25 的连接分量被视为噪声的噪声。

## 8 adjacency connectivity method to search the document image.
connectivity = 8                  

## find the connected components 

output = cv2.connectedComponentsWithStats(invr_binary, connectivity, cv2.CV_32S) 
## it contain fou variable

(numLabels, labels, stats, centroids) = output

我无法理解的下一步是什么?

标签: pythonimage-processingopencv-python

解决方案


我已经使用统计信息来消除噪音。统计信息:每个连接组件的统计信息,包括边界框坐标和面积(以像素为单位)。

def imshow(image):
    plt.figure(figsize=(20,10)
    plt.imshow(image)

areas = stats[1:,cv2.CC_STAT_AREA]
result = np.zeros((labels.shape), np.uint8)
for i in range(0, numLabels - 1):
    if areas[i] >= 25:   #keep
    result[labels == i + 1] = 255
imshow(result)

推荐阅读