lungs_var3_d8g_222f.py 文件源码

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

项目:kaggle_dsb2017 作者: astoc 项目源码 文件源码
def cut_out_non_lungs_z (images3, pmasks3, images3_seg, uid, dim):
    HU_LUNGS_MIN = -900  # the algo is sensitive to this value -- keep it 900 unless retested
    HU_LUNGS_MAX = -400

    pix_lungs_min = hu_to_pix(HU_LUNGS_MIN)
    pix_lungs_max = hu_to_pix(HU_LUNGS_MAX)

    mid = dim // 2    

    ymin = int(0.4 * images3.shape[3])  ## BUG was 4
    ymax = int(0.6 * images3.shape[3])  ## # waut it failed for tne one following 4b351d0c19be183cc880f5af3fe5abee ( index 240 is out of bounds for axis 3 with size 240)
    zmin_new = images3.shape[0] // 2
    zmax_new = images3.shape[0] // 2
    j = ymin
    for j in range(ymin, ymax+1):   
         img_cut = images3[:,0,mid, j]
         img_cut_lungs = (img_cut > pix_lungs_min) & (img_cut < pix_lungs_max)
         lungs_across = np.sum(img_cut_lungs, axis = 1)
         noise_bottom_some = np.mean(lungs_across[0:10])  # increase by 2
         noise = np.max([3*np.min(lungs_across), 0.05 * np.max(lungs_across), noise_bottom_some])  # experimanetal -- could fail is scan has only central part of lungs and no borders at all -- CHECK
         zmin, zmax = find_lungs_range(lungs_across, noise)
         if zmin < zmin_new:
             zmin_new = zmin
         if zmax > zmax_new:
             #print ("j, zmax: ", j, zmax)
             zmax_new = zmax

    ### do not cut it to fine (add few pixels on each side ...)
    zmin_new = np.max([0, zmin_new-mid])
    zmax_new = np.min([images3.shape[0], zmax_new+mid])
    print("cut_out_non_lungs_z from to:", images3.shape[0], zmin_new, zmax_new, uid )
    if ((zmax_new-zmin_new)/images3.shape[0] < 0.5):
            print ("SUSPICSIOUS large cut of > 50%, NOT executing ...")
    else:
        images3 = images3[zmin_new:zmax_new]
        pmasks3 = pmasks3[zmin_new:zmax_new]
        images3_seg = images3_seg[zmin_new:zmax_new]

    return images3, pmasks3, images3_seg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号