Python scipy.ndimage 模块,grey_dilation() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用scipy.ndimage.grey_dilation()

项目:CNNbasedMedicalSegmentation    作者:BRML    | 项目源码 | 文件源码
def show_transform():
    for im in gen_images(n=-1, crop=True):
        t_im = im['T1c']
        gt = im['gt']
        #t_im_trans, trans_gt = rotate_transform(t_im, gt)
        #t_im_trans = t_im
        #t_im_trans = re_rescale(t_im)
        #t_im_trans = flip(t_im)
        #t_im_trans = noise(t_im, intensity=1, n=10)
        t_im_trans, trans_gt = ndi.percentile_filter(t_im, np.random.randint(0, 10), (2, 2, 2)), gt
        #t_im_trans = ndi.morphological_gradient(t_im, size=(2, 2, 2))
        #t_im_trans = ndi.grey_dilation(t_im, size=(3, 3, 3))
        #t_im_trans = ndi.grey_erosion(t_im_trans, size=(3, 3, 3))

        print t_im_trans.dtype

        for _slice in np.arange(0, t_im.shape[0], t_im.shape[0]/20):
            im_slice = t_im[_slice]
            im_slice_trans = t_im_trans[_slice]
            gt_slice = gt[_slice]
            trans_gt_slice = trans_gt[_slice]

            vis_ims(im0=im_slice, gt0=gt_slice, im1=im_slice_trans, gt1=trans_gt_slice)
项目:word-render    作者:eragonruan    | 项目源码 | 文件源码
def get_bordershadow(self, bg_arr, colour):
        """
        Gets a border/shadow with the movement state [top, right, bottom, left].
        Inset or outset is random.
        """
        bs = self.borderstate.get_sample()
        outset = bs['outset']
        width = bs['width']
        position = bs['position']

        # make a copy
        border_arr = bg_arr.copy()
        # re-colour
        border_arr[..., 0] = colour
        if outset:
            # dilate black (erode white)
            border_arr[..., 1] = ndimage.grey_dilation(border_arr[..., 1], size=(width, width))
            border_arr = self.arr_scroll(border_arr, position[0], position[1])

            return border_arr, bg_arr
        else:
            # erode black (dilate white)
            border_arr[..., 1] = ndimage.grey_erosion(border_arr[..., 1], size=(width, width))
            return bg_arr, border_arr
项目:word-render    作者:eragonruan    | 项目源码 | 文件源码
def get_bordershadow(self, bg_arr, colour):
        """
        Gets a border/shadow with the movement state [top, right, bottom, left].
        Inset or outset is random.
        """
        bs = self.borderstate.get_sample()
        outset = bs['outset']
        width = bs['width']
        position = bs['position']

        # make a copy
        border_arr = bg_arr.copy()
        # re-colour
        border_arr[..., 0] = colour
        if outset:
            # dilate black (erode white)
            border_arr[..., 1] = ndimage.grey_dilation(border_arr[..., 1], size=(width, width))
            border_arr = self.arr_scroll(border_arr, position[0], position[1])

            return border_arr, bg_arr
        else:
            # erode black (dilate white)
            border_arr[..., 1] = ndimage.grey_erosion(border_arr[..., 1], size=(width, width))
            return bg_arr, border_arr
项目:Deep-Image-Matting    作者:Joker316701882    | 项目源码 | 文件源码
def generate_trimap(trimap,alpha):

    k_size = random.choice(trimap_kernel)
    # trimap[np.where((ndimage.grey_dilation(alpha[:,:,0],size=(k_size,k_size)) - ndimage.grey_erosion(alpha[:,:,0],size=(k_size,k_size)))!=0)] = 128
    trimap[np.where((ndimage.grey_dilation(alpha[:,:,0],size=(k_size,k_size)) - alpha[:,:,0]!=0))] = 128
    return trimap
项目:MLUtil    作者:WarBean    | 项目源码 | 文件源码
def grey_dilation(func_config):
    def f(image_config):
        s1 = random.randrange(func_config.min_size, func_config.max_size + 1)
        s2 = random.randrange(func_config.min_size, func_config.max_size + 1)
        array = ndimage.grey_dilation(image_config.image, size = (s1, s2))
        image = Image.fromarray(array)
        image_config.image = image
    return f
项目:text-renderer    作者:cjnolet    | 项目源码 | 文件源码
def get_bordershadow(self, bg_arr, colour):
        """
        Gets a border/shadow with the movement state [top, right, bottom, left].
        Inset or outset is random.
        """
        bs = self.borderstate.get_sample()
        outset = bs['outset']
        width = bs['width']
        position = bs['position']

        # make a copy
        border_arr = bg_arr.copy()
        # re-colour
        border_arr[...,0] = colour
        if outset:
            # dilate black (erode white)
            border_arr[...,1] = ndimage.grey_dilation(border_arr[...,1], size=(width, width))
            border_arr = self.arr_scroll(border_arr, position[0], position[1])

            # canvas = 255*n.ones(bg_arr.shape)
            # canvas = grey_blit(border_arr, canvas)
            # canvas = grey_blit(bg_arr, canvas)
            # pyplot.imshow(canvas[...,0], cmap=cm.Greys_r)
            # pyplot.show()

            return border_arr, bg_arr
        else:
            # erode black (dilate white)
            border_arr[...,1] = ndimage.grey_erosion(border_arr[...,1], size=(width, width))
            return bg_arr, border_arr
项目:antares    作者:CONABIO    | 项目源码 | 文件源码
def morph_dilation(input_image_raster, filter_size):
    '''
    Morphological dilation of raster
    '''
    ndim = 3
    if input_image_raster.ndim == 2:
        input_image_raster = numpy.expand_dims(input_image_raster, axis=0)
        ndim = 2
    if input_image_raster.ndim != 3:
        raise Exception("Input array has to be 3D")
    if ndim == 3:
        return ndimage.grey_dilation(input_image_raster, (1, filter_size, filter_size))
    else:
        return ndimage.grey_dilation(input_image_raster, (1, filter_size, filter_size))[0]