]> mj.ucw.cz Git - libucw.git/blob - images/images.h
763006d9d4cc200158d192a6810f82bfda412480
[libucw.git] / images / images.h
1 #ifndef _IMAGES_IMAGES_H
2 #define _IMAGES_IMAGES_H
3
4 #include <alloca.h>
5 #include <stdio.h>
6
7 #define IMAGE_VEC_K     6
8 #define IMAGE_REG_K     9
9 #define IMAGE_REG_MAX   4
10
11 typedef u16 image_feature_t;    /* 8 or 16 bits precision */
12
13 /* K-dimensional feature vector */
14 struct image_vector {
15   image_feature_t f[IMAGE_VEC_K];
16 };
17
18 /* K-dimensional interval */
19 struct image_bbox {
20   struct image_vector vec[2];
21 };
22
23 /* Fetures for image regions */
24 struct image_region {
25   image_feature_t f[IMAGE_REG_K];
26 };
27
28 /* Image signature */
29 struct image_signature {
30   struct image_vector vec;      /* Combination of all regions... simplier signature */
31   image_feature_t len;          /* Number of regions */
32   struct image_region reg[IMAGE_REG_MAX];/* Feature vector for every region */
33 };
34
35 /* Similarity search tree... will be changed */
36 struct image_tree {
37   uns count;                    /* Number of images in the tree */
38   uns depth;                    /* Tree depth */
39   struct image_bbox bbox;       /* Bounding box containing all the */
40   struct image_node *nodes;     /* Internal nodes */
41   struct image_leaf *leaves;    /* Leaves */
42 };
43
44 /* Internal node in the search tree */
45 #define IMAGE_NODE_LEAF         0x80000000              /* Node contains pointer to leaves array */
46 #define IMAGE_NODE_DIM          0xff                    /* Split dimension */
47 struct image_node {
48   u32 val;
49 };
50
51 /* Leaves in the search tree */
52 #define IMAGE_LEAF_LAST         0x80000000              /* Last entry in the list */
53 #define IMAGE_LEAF_BITS(i)      (31 / IMAGE_VEC_K)      /* Number of bits for relative position in i-th dimension */
54 struct image_leaf {
55   u32 flags;            /* Relative position in bbox and last node flag */ 
56   oid_t oid;
57 };
58
59 #define stk_print_image_vector(v) ({ struct image_vector *_v = v; \
60     byte *_s = (byte *) alloca(IMAGE_VEC_K * 6), *_p = _s + sprintf(_s, "%d", _v->f[0]); \
61     for (uns _i = 1; _i < IMAGE_VEC_K; _i++) _p += sprintf(_p, " %d", _v->f[_i]); _s; })
62
63 extern struct image_tree image_tree;
64
65 void image_tree_init(void);
66 void image_tree_done(void);
67
68 void compute_image_signature_prepare(void);
69 void compute_image_signature_finish(void);
70 int compute_image_signature(void *data, uns len, struct image_signature *sig);
71
72 #endif
73