dsb_utils.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:diagnose-heart 作者: woshialex 项目源码 文件源码
def clean_segmentation(segments, img_size, thresh):
    mean = segments.mean(axis=(0,1))
    gaussian_params = gaussian_moments_fake(mean, normalize_height=True)
    pdf = gaussian_pdf(*gaussian_params)
    seg_binary = np.zeros_like(segments)
    pdf_dict = np.zeros_like(mean)
    for x in xrange(mean.shape[0]):
        for y in xrange(mean.shape[1]):
            pdf_dict[x,y] = pdf(x,y)
    for i in xrange(segments.shape[0]):
        _,sb = cv2.threshold(np.copy(segments[i,0])*255, 127, 255, cv2.THRESH_BINARY)
        patches = get_patches(sb)
        if len(patches)==0:
            continue
        sum_pdf_vals = [sum(pdf_dict[x,y] for x,y in p) for p in patches]
        avg_pdf_vals = [sum(pdf_dict[x,y] for x,y in p)/p.shape[0] for p in patches]
        max_sum_pdf = max(sum_pdf_vals)
        for p_idx, p in enumerate(patches):
            if avg_pdf_vals[p_idx] < 0.07 or sum_pdf_vals[p_idx] < max_sum_pdf:
                for x,y in p:
                    seg_binary[i,0,x,y]=0
            else:
                for x,y in p:
                    seg_binary[i,0,x,y]=1
    return seg_binary
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号