]> mj.ucw.cz Git - libucw.git/blob - images/signature.h
scanner generates tree new files - image signatures (for similarity detection),
[libucw.git] / images / signature.h
1 #ifndef _IMAGES_SIGNATURE_H
2 #define _IMAGES_SIGNATURE_H
3
4 #define IMAGE_VEC_F     6
5 #define IMAGE_REG_F     IMAGE_VEC_F
6 #define IMAGE_REG_H     3
7 #define IMAGE_REG_MAX   8
8
9 /* K-dimensional feature vector (6 bytes) */
10 struct image_vector {
11   byte f[IMAGE_VEC_F];          /* texture features */
12 } PACKED;
13
14 /* Fetures for image regions (16 bytes) */
15 struct image_region {
16   byte f[IMAGE_VEC_F];          /* texture features */
17   u16 h[IMAGE_REG_H];           /* shape features */
18   u16 wa;                       /* normalized area percentage */
19   u16 wb;                       /* normalized weight */
20 } PACKED;
21
22 /* Image signature (10 + len * 16 bytes) */
23 struct image_signature {
24   byte len;                     /* Number of regions */
25   byte df;                      /* average f dist */
26   u16 dh;                       /* average h dist */
27   struct image_vector vec;      /* Combination of all regions... simple signature */
28   struct image_region reg[IMAGE_REG_MAX];/* Feature vector for every region */
29 } PACKED;
30
31 static inline uns
32 image_signature_size(uns len)
33 {
34   return 4 + sizeof(struct image_vector) + len * sizeof(struct image_region);
35 }
36
37 /* sig-dump.c */
38
39 #define IMAGE_VECTOR_DUMP_MAX (IMAGE_VEC_F * 16 + 1)
40 #define IMAGE_REGION_DUMP_MAX ((IMAGE_REG_F + IMAGE_REG_H) * 16 + 100)
41
42 byte *image_vector_dump(byte *buf, struct image_vector *vec);
43 byte *image_region_dump(byte *buf, struct image_region *reg);
44
45 /* sig-init.c */
46
47 int compute_image_signature(struct image_thread *thread, struct image_signature *sig, struct image *image);
48
49 /* sig-cmp.c */
50
51 #define IMAGE_SIG_DIST_SCALE (3 + 3 + 8 + 16)
52
53 uns image_signatures_dist(struct image_signature *sig1, struct image_signature *sig2);
54
55 #if 0
56 /* K-dimensional interval */
57 struct image_bbox {
58   struct image_vector vec[2];
59 };
60
61 /* Similarity search tree... will be changed */
62 struct image_tree {
63   uns count;                    /* Number of images in the tree */
64   uns depth;                    /* Tree depth */
65   struct image_bbox bbox;       /* Bounding box containing all the */
66   struct image_node *nodes;     /* Internal nodes */
67   struct image_leaf *leaves;    /* Leaves */
68 };
69
70 /* Internal node in the search tree */
71 #define IMAGE_NODE_LEAF         0x80000000              /* Node contains pointer to leaves array */
72 #define IMAGE_NODE_DIM          0xff                    /* Split dimension */
73 struct image_node {
74   u32 val;
75 };
76
77 /* Leaves in the search tree */
78 #define IMAGE_LEAF_LAST         0x80000000              /* Last entry in the list */
79 #define IMAGE_LEAF_BITS(i)      (31 / IMAGE_VEC_K)      /* Number of bits for relative position in i-th dimension */
80 struct image_leaf {
81   u32 flags;            /* Relative position in bbox and last node flag */ 
82   oid_t oid;
83 };
84
85 #define stk_print_image_vector(v) ({ struct image_vector *_v = v; \
86     byte *_s = (byte *) alloca(IMAGE_VEC_K * 6), *_p = _s + sprintf(_s, "%d", _v->f[0]); \
87     for (uns _i = 1; _i < IMAGE_VEC_K; _i++) _p += sprintf(_p, " %d", _v->f[_i]); _s; })
88 #endif
89
90 #endif
91