3 #define MSG(x...) do{}while(0)
6 image_signatures_dist_2(struct image_signature *sig1, struct image_signature *sig2)
10 #define MSG(x...) bprintf(fb, x)
13 dump_signature(struct image_signature *sig, struct fastbuf *fb)
15 MSG("signature: flags=0x%x df=%u dh=%u f=(%u", sig->flags, sig->df, sig->dh, sig->vec.f[0]);
16 for (uns i = 1; i < IMAGE_VEC_F; i++)
17 MSG(" %u", sig->vec.f[i]);
19 for (uns j = 0; j < sig->len; j++)
21 struct image_region *reg = sig->reg + j;
22 MSG("region %u: wa=%u wb=%u f=(%u", j, reg->wa, reg->wb, reg->f[0]);
23 for (uns i = 1; i < IMAGE_VEC_F; i++)
24 MSG(" %u", reg->f[i]);
25 MSG(") h=(%u", reg->h[0]);
26 for (uns i = 1; i < IMAGE_REG_H; i++)
27 MSG(" %u", reg->h[i]);
33 image_signatures_dist_2_explain(struct image_signature *sig1, struct image_signature *sig2, struct fastbuf *fb)
37 DBG("image_signatures_dist_2()");
39 uns dist[IMAGE_REG_MAX * IMAGE_REG_MAX], p[IMAGE_REG_MAX], q[IMAGE_REG_MAX];
40 uns n, i, j, k, l, s, d;
41 struct image_region *reg1, *reg2;
44 dump_signature(sig1, fb);
45 dump_signature(sig2, fb);
48 /* Compute distance matrix */
50 MSG("Distance matrix:\n");
51 /* ... for non-textured images */
52 if (!((sig1->flags | sig2->flags) & IMAGE_SIG_TEXTURED))
53 for (j = 0, reg2 = sig2->reg; j < sig2->len; j++, reg2++)
54 for (i = 0, reg1 = sig1->reg; i < sig1->len; i++, reg1++)
57 isqr((int)reg1->h[0] - (int)reg2->h[0]) +
58 isqr((int)reg1->h[1] - (int)reg2->h[1]) +
59 isqr((int)reg1->h[2] - (int)reg2->h[2]);
61 isqr((int)reg1->f[0] - (int)reg2->f[0]) +
62 isqr((int)reg1->f[1] - (int)reg2->f[1]) +
63 isqr((int)reg1->f[2] - (int)reg2->f[2]) +
64 isqr((int)reg1->f[3] - (int)reg2->f[3]) +
65 isqr((int)reg1->f[4] - (int)reg2->f[4]) +
66 isqr((int)reg1->f[5] - (int)reg2->f[5]);
73 DBG("[%u][%u] ... dt=%u ds=%u", i, j, dt, ds);
74 dist[n++] = (dt << 8) + i + (j << 4);
75 MSG("[%u, %u] ... dt=%u ds=%u\n", i, j, dt, ds);
77 /* ... for textured images (ignore shape properties) */
79 for (j = 0, reg2 = sig2->reg; j < sig2->len; j++, reg2++)
80 for (i = 0, reg1 = sig1->reg; i < sig1->len; i++, reg1++)
83 isqr((int)reg1->f[0] - (int)reg2->f[0]) +
84 isqr((int)reg1->f[1] - (int)reg2->f[1]) +
85 isqr((int)reg1->f[2] - (int)reg2->f[2]) +
86 isqr((int)reg1->f[3] - (int)reg2->f[3]) +
87 isqr((int)reg1->f[4] - (int)reg2->f[4]) +
88 isqr((int)reg1->f[5] - (int)reg2->f[5]);
89 dist[n++] = (dt << 12) + i + (j << 4);
90 MSG("[%u, %u] ... dt=%u\n", i, j, dt);
93 /* One or both signatures have no regions */
98 for (i = 0, reg1 = sig1->reg; i < sig1->len; i++, reg1++)
100 for (i = 0, reg2 = sig2->reg; i < sig2->len; i++, reg2++)
103 /* Sort entries in distance matrix */
104 image_signatures_dist_2_sort(n, dist);
106 /* Compute significance matrix and resulting distance */
108 MSG("Significance matrix:\n");
109 for (k = 0, l = 128; l; k++)
112 j = (dist[k] >> 4) & 15;
128 DBG("s[%u][%u]=%u d=%u", i, j, s, d);
129 MSG("[%u, %u]=%u d=%u\n", i, j, s, d);