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)
python类grey_erosion()的实例源码
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
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
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
def grey_erosion(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_erosion(image_config.image, size = (s1, s2))
image = Image.fromarray(array)
image_config.image = image
return f
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