python类erosion()的实例源码

plot_spectra.py 文件源码 项目:DR1_analysis 作者: GBTAmmoniaSurvey 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def trim_edge_cube(cube):
    """  trim_edge_cube: Function that reads in a cube and removes the edges 
    in the cube. 
    It runs the erode function to make sure that pixels within 3 pixels away 
    from the edges are blanked. 
    This is useful to remove very noisy pixels due to lower coverage by KFPA.
    ----------------------------------------
    Warning: This function modifies the cube.
    """
    # 
    mask = np.isfinite(cube)
    if len(cube.shape) == 2:
        mask_2d = mask[:,:]
    else:
        mask_2d = mask[0,:,:]
    # remove image edges
    mask_2d[:,0] = mask_2d[:,-1] = False
    mask_2d[0,:] = mask_2d[-1,:] = False
    # now erode image (using disk) and convert back to 3D mask
    # then replace all voxels with NaN
    mask &= erosion(mask_2d,disk(5))
    cube[~mask] = np.nan
prepro.py 文件源码 项目:tensorlayer-chinese 作者: shorxp 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def erosion(x, radius=3):
    """ Return greyscale morphological erosion of an image,
    see `skimage.morphology.erosion <http://scikit-image.org/docs/dev/api/skimage.morphology.html#skimage.morphology.erosion>`_.

    Parameters
    -----------
    x : 2D array image.
    radius : int for the radius of mask.
    """
    from skimage.morphology import disk, dilation, erosion
    mask = disk(radius)
    x = erosion(x, selem=mask)
    return x



## Object Detection
voxel_extract.py 文件源码 项目:data-science-bowl-2017 作者: tondonia 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def extract_voxels(images,pred_1,truths=None):
    eroded = morphology.erosion(pred_1,np.ones([3,3,3]))
    dilation = morphology.dilation(eroded,np.ones([3,3,3]))
    labels = measure.label(dilation) # Different labels are displayed in different colors
    label_vals = np.unique(labels)
    regions = measure.regionprops(labels)
    kept = 0
    removed = 0
    data = []
    for idx in range(len(regions)):
        b = regions[idx].bbox
        if regions[idx].area < 50:
            removed += 1
            continue
        kept += 1
        print "before->",b
        b = get_bounding_box(b,images.shape)
        print "after->",b
        image_voxel = images[b[0]:b[3],b[1]:b[4],b[2]:b[5]]
        label = 0
        if not truths is None:
            print "finding region in truths"
            truth_voxel = truths[b[0]:b[3],b[1]:b[4],b[2]:b[5]]
            nonzeros = np.count_nonzero(truth_voxel)
            if nonzeros > 0:
                label = 1
        assert(image_voxel.size==(VOXEL_DEPTH*VOXEL_DEPTH*VOXEL_DEPTH))
        print "Appending voxel with label ",label
        data.append((image_voxel,label,b))
    print "kept",kept,"removed",removed
    sys.stdout.flush()            
    return data
prepro.py 文件源码 项目:tensorlayer-chinese 作者: shorxp 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def binary_erosion(x, radius=3):
    """ Return binary morphological erosion of an image,
    see `skimage.morphology.binary_erosion <http://scikit-image.org/docs/dev/api/skimage.morphology.html#skimage.morphology.binary_erosion>`_.

    Parameters
    -----------
    x : 2D array image.
    radius : int for the radius of mask.
    """
    from skimage.morphology import disk, dilation, binary_erosion
    mask = disk(radius)
    x = binary_erosion(x, selem=mask)
    return x
image_tfs.py 文件源码 项目:tanda 作者: HazyResearch 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def TF_erosion(img):
    return erosion(img)


问题


面经


文章

微信
公众号

扫码关注公众号