行走的蓑衣客

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
统计
 
复制代码
from skimage import measure
import cv2
import numpy as np
 
##
##image:二值图像
##threshold_point:符合面积条件大小的阈值
def remove_small_points(image,threshold_point):
    img = cv2.imread(image, 0)       #输入的二值图像
    img_label, num = measure.label(img, neighbors=8, return_num=True)#输出二值图像中所有的连通域
    props = measure.regionprops(img_label)#输出连通域的属性,包括面积等
 
    resMatrix = np.zeros(img_label.shape)
    for i in range(1, len(props)):
        if props[i].area > threshold_point:
            tmp = (img_label == i + 1).astype(np.uint8)
            resMatrix += tmp #组合所有符合条件的连通域
    resMatrix *= 255
    return resMatrix
 
res = remove_small_points(image,threshold_point)
 
复制代码

 

posted on   行走的蓑衣客  阅读(431)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
 
点击右上角即可分享
微信分享提示