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