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