python - 如何去除图像中的噪声以设置连通分量中的像素值?
问题描述
我在输入图像上应用了 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
我无法理解的下一步是什么?
解决方案
我已经使用统计信息来消除噪音。统计信息:每个连接组件的统计信息,包括边界框坐标和面积(以像素为单位)。
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)
推荐阅读
- python - 生成器理解忽略类范围
- node.js - 在 npm 开发构建中反应应用程序部署错误
- node.js - 集成测试 node.js socket.io 服务器
- c# - Docker for C# core (linux type) 行为 - 与镜像构建相关
- angular - Angular 7 CLI 以编程方式
- html - 显示当前 div 侧边栏
- codenameone - QRScanner 使用前置摄像头
- django - Django CreateView - created_by,modified_by mixin 不起作用
- java - 迁移到 androidx 后的 ClassNotFoundException
- python - 如何在python中对月份列进行排序后找到平均值