Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def compute_results_for_window(matrix):
- """
- 3x3 windows
- :return:
- """
- # 85
- matrix_shape = matrix.shape
- intersection_indexes = dict()
- # Row iteration NOTE: beware that you might not be able to iterate complete steps if the marix shape dosen't go with 3
- i = 0
- while i < matrix_shape[0]:
- # Column iteration
- j = 0
- while j < matrix_shape[1]:
- intersection_indexes[(i, j)] = None
- window = matrix[i : i+3][j : j+3]
- window_sum = np.sum(window)
- if window_sum > 3:
- intersection_indexes[((i, i+3), (j, j+3))] = 3
- else:
- found_horizontal = False
- for row in window:
- if np.sum(row) == 3:
- intersection_indexes[((i, i+3), (j, j+3))] = 2
- found_horizontal = True
- break
- if not found_horizontal:
- for column in np.rot90(window):
- if np.sum(column) == 3:
- intersection_indexes[((i, i+3), (j, j+3))] = 1
- break
- j += 1
- i += 1
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement