-
Notifications
You must be signed in to change notification settings - Fork 2
/
feature_descriptor_histogram_interpolate.c
119 lines (93 loc) · 2.13 KB
/
feature_descriptor_histogram_interpolate.c
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "header.h"
#include "proto.h"
void feature_descriptor_histogram_interpolate(
double ***hist_arr,
double descr_i_sub,
double descr_j_sub,
double hist_ind_sub,
double mag,
int descr_width,
int hist_nbr
)
/*
Distribute mag in a trilinear fashion
*/
{
int descr_i_sub_floor;
int descr_j_sub_floor;
int hist_ind_sub_floor;
int i_offset;
int j_offset;
int h_offset;
int descr_i;
int descr_j;
int hist_ind;
double val_i;
double val_j;
double val_h;
double diff_i;
double diff_j;
double diff_h;
/*
Get the floor of descr_i_sub
*/
if ( descr_i_sub >= 0 )
descr_i_sub_floor= (int)descr_i_sub;
else
descr_i_sub_floor= (int)descr_i_sub-1;
/*
Get the floor of descr_j_sub
*/
if ( descr_j_sub >= 0 )
descr_j_sub_floor= (int)descr_j_sub;
else
descr_j_sub_floor= (int)descr_j_sub-1;
/*
Get the floor of hist_ind_sub
*/
if ( hist_ind_sub >= 0 )
hist_ind_sub_floor= (int)hist_ind_sub;
else
hist_ind_sub_floor= (int)hist_ind_sub-1;
/*
Compute the differences
(between sub value and floor)
*/
diff_i= descr_i_sub-(double)descr_i_sub_floor;
diff_j= descr_j_sub-(double)descr_j_sub_floor;
diff_h= hist_ind_sub-(double)hist_ind_sub_floor;
for ( i_offset= 0 ; i_offset<= 1 ; i_offset++ ) {
descr_i= descr_i_sub_floor+i_offset;
if ( !( descr_i >= 0 &&
descr_i < descr_width ) )
continue;
if ( i_offset == 0 ) {
val_i= 1-diff_i;
}
if ( i_offset == 1 ) {
val_i= diff_i;
}
for ( j_offset= 0 ; j_offset<= 1 ; j_offset++ ) {
descr_j= descr_j_sub_floor+j_offset;
if ( !( descr_j >= 0 &&
descr_j < descr_width ) )
continue;
if ( j_offset == 0 ) {
val_j= 1-diff_j;
}
if ( j_offset == 1 ) {
val_j= diff_j;
}
for ( h_offset= 0 ; h_offset<= 1 ; h_offset++ ) {
hist_ind= (hist_ind_sub_floor+h_offset)%hist_nbr;
if ( h_offset == 0 ) {
val_h= 1-diff_h;
}
if ( h_offset == 1 ) {
val_h= diff_h;
}
hist_arr[descr_i][descr_j][hist_ind]+= val_i*val_j*val_h*mag;
}
}
}
}