Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. # code1
  2. def filter(img, func, ksize, strides=1):
  3. height,width = img.shape
  4. f_height,f_width = ksize
  5. new_height = height - f_height + 1
  6. new_width = width - f_width + 1
  7.  
  8. new_img = np.zeros((new_height,new_width))
  9.  
  10. for i in range(new_height):
  11. for j in range(new_width):
  12. patch = img[i:i+f_height,j:j+f_width]
  13. new_img[i][j] = func(patch)
  14.  
  15. return new_img
  16.  
  17. # code2
  18. def relative_median_and_center_diff(patch, in_the_boundary, rectangle, center_point):
  19. mask = patch == 255
  20. mask[center_point] = True
  21. masked_patch = np.ma.array(patch, mask=mask)
  22. count = masked_patch.count()
  23. if count <= 1:
  24. return 0
  25. else:
  26. return patch[center_point]/(np.ma.median(masked_patch)+1)
  27.  
  28. # code3
  29. def filter(img, func, ksize, strides=1):
  30. height,width = img.shape
  31. f_height,f_width = ksize
  32. new_height = height - f_height + 1
  33. new_width = width - f_width + 1
  34.  
  35. new_img = np.zeros((new_height,new_width))
  36.  
  37. from skimage.util.shape import view_as_windows
  38. patches = view_as_windows(img, (f_height,f_width))
  39.  
  40. for i in range(new_height):
  41. for j in range(new_width):
  42. patch = patches[i,j]
  43. new_img[i][j] = func(patch)
  44.  
  45. return new_img
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement