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