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