Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # code1
- def filter(img, func, ksize, strides=1):
- height,width = img.shape
- f_height,f_width = ksize
- new_height = height - f_height + 1
- new_width = width - f_width + 1
- new_img = np.zeros((new_height,new_width))
- for i in range(new_height):
- for j in range(new_width):
- patch = img[i:i+f_height,j:j+f_width]
- new_img[i][j] = func(patch)
- return new_img
- # code2
- def relative_median_and_center_diff(patch, in_the_boundary, rectangle, center_point):
- mask = patch == 255
- mask[center_point] = True
- masked_patch = np.ma.array(patch, mask=mask)
- count = masked_patch.count()
- if count <= 1:
- return 0
- else:
- return patch[center_point]/(np.ma.median(masked_patch)+1)
- # code3
- def filter(img, func, ksize, strides=1):
- height,width = img.shape
- f_height,f_width = ksize
- new_height = height - f_height + 1
- new_width = width - f_width + 1
- new_img = np.zeros((new_height,new_width))
- from skimage.util.shape import view_as_windows
- patches = view_as_windows(img, (f_height,f_width))
- for i in range(new_height):
- for j in range(new_width):
- patch = patches[i,j]
- new_img[i][j] = func(patch)
- return new_img
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement