-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmp.cpp
64 lines (51 loc) · 1.55 KB
/
cmp.cpp
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
#include <cmath>
#include <stdlib.h>
#include <string.h>
#include "cmp.h"
#include "haar.h"
unsigned char imgBin[NUM_PIXELS_SQUARED];
int imgBinInited = 0;
void initImgBin() {
imgBinInited = 1;
/* setup initial fixed weights that each coefficient represents */
int i, j;
/*
0 1 2 3 4 5 6 i
0 0 1 2 3 4 5 5
1 1 1 2 3 4 5 5
2 2 2 2 3 4 5 5
3 3 3 3 3 4 5 5
4 4 4 4 4 4 5 5
5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5
j
*/
/* Every position has value 5, */
memset(imgBin, 5, NUM_PIXELS_SQUARED);
/* Except for the 5 by 5 upper-left quadrant: */
for (i = 0; i < 5; i++)
for (j = 0; j < 5; j++)
imgBin[i * NUM_PIXELS + j] = max(i, j);
// Note: imgBin[0] == 0
}
double calcDiff(SigStruct *siga, SigStruct *sigb) {
/* use it to tell the content-based difference between two images
*/
if (!imgBinInited) {
initImgBin();
}
double diff = calcAvglDiff(siga, sigb);
Idx *corea[3] = { siga->sig1, siga->sig2, siga->sig3 };
Idx *coreb[3] = { sigb->sig1, sigb->sig2, sigb->sig3 };
for (int b = 0; b < NUM_COEFS; b++)
for (int c = 0; c < 3; c++)
for (int b2 = 0; b2 < NUM_COEFS; b2++)
if (coreb[c][b2] == corea[c][b])
diff -= picture_weights[imgBin[abs(corea[c][b])]][c];
return diff;
}
double calcAvglDiff(SigStruct *siga, SigStruct *sigb) {
return fabs(siga->avgl[0] - sigb->avgl[0])
+ fabs(siga->avgl[1] - sigb->avgl[1])
+ fabs(siga->avgl[2] - sigb->avgl[2]);
}