-
Notifications
You must be signed in to change notification settings - Fork 6
/
computeIntegralImageScores.py
33 lines (27 loc) · 1.21 KB
/
computeIntegralImageScores.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
import numpy as np
def compute_integral_img_scores(integral_img, windows):
"""
Computes the score of the windows wrt the integral_img
:param integral_img:
:param windows: (x1, y1, x2, y2)
:return:
"""
windows = np.round(windows).astype(np.int)
windows[windows == 0] = 1
windows -= 1 # From matlab indices to numpy indices
width = integral_img.shape[1]
integral_img = integral_img.reshape(-1)
# The -1 is to transform the matlab index to numpy index
index1 = width * (windows[:, 3] + 1) + windows[:, 2]
index2 = width * (windows[:, 1]) + windows[:, 0] - 1
index3 = width * (windows[:, 3] + 1) + windows[:, 0] - 1
index4 = width * (windows[:, 1]) + windows[:, 2]
# Original matlab code:
# integral_img = integral_img.T.reshape(-1)
# height = integral_img.shape[0]
# index1 = height * windows[:, 2] + (windows[:, 3] + 1)
# index2 = height * (windows[:, 0] - 1) + windows[:, 1]
# index3 = height * (windows[:, 0] - 1) + (windows[:, 3] + 1)
# index4 = height * windows[:, 2] + windows[:, 1]
score = integral_img[index1] + integral_img[index2] - integral_img[index3] - integral_img[index4]
return score