Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. def compute_results_for_window(matrix):
  2. """
  3. 3x3 windows
  4.  
  5. :return:
  6. """
  7.  
  8. # 85
  9. matrix_shape = matrix.shape
  10.  
  11. intersection_indexes = dict()
  12.  
  13. # Row iteration NOTE: beware that you might not be able to iterate complete steps if the marix shape dosen't go with 3
  14. i = 0
  15. while i < matrix_shape[0]:
  16. # Column iteration
  17. j = 0
  18. while j < matrix_shape[1]:
  19. intersection_indexes[(i, j)] = None
  20. window = matrix[i : i+3][j : j+3]
  21. window_sum = np.sum(window)
  22.  
  23. if window_sum > 3:
  24. intersection_indexes[((i, i+3), (j, j+3))] = 3
  25.  
  26. else:
  27. found_horizontal = False
  28. for row in window:
  29. if np.sum(row) == 3:
  30. intersection_indexes[((i, i+3), (j, j+3))] = 2
  31. found_horizontal = True
  32. break
  33.  
  34. if not found_horizontal:
  35. for column in np.rot90(window):
  36. if np.sum(column) == 3:
  37. intersection_indexes[((i, i+3), (j, j+3))] = 1
  38. break
  39.  
  40. j += 1
  41.  
  42. i += 1
  43.  
  44. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement