-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract_samll_cubic.py
37 lines (27 loc) · 1.21 KB
/
extract_samll_cubic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Created on Wed Oct 21 21:10:24 2020
@author: xuegeeker
@blog: https://github.com/xuegeeker
@email: xuegeeker@163.com
"""
import numpy as np
def index_assignment(index, row, col, pad_length):
new_assign = {}
for counter, value in enumerate(index):
assign_0 = value // col + pad_length
assign_1 = value % col + pad_length
new_assign[counter] = [assign_0, assign_1]
return new_assign
def assignment_index(assign_0, assign_1, col):
new_index = assign_0 * col + assign_1
return new_index
def select_patch(matrix, pos_row, pos_col, ex_len):
selected_rows = matrix[range(pos_row-ex_len, pos_row+ex_len+1)]
selected_patch = selected_rows[:, range(pos_col-ex_len, pos_col+ex_len+1)]
return selected_patch
def select_small_cubic(data_size, data_indices, whole_data, patch_length, padded_data, dimension):
small_cubic_data = np.zeros((data_size, 2 * patch_length + 1, 2 * patch_length + 1, dimension))
data_assign = index_assignment(data_indices, whole_data.shape[0], whole_data.shape[1], patch_length)
for i in range(len(data_assign)):
small_cubic_data[i] = select_patch(padded_data, data_assign[i][0], data_assign[i][1], patch_length)
return small_cubic_data