]> mj.ucw.cz Git - libucw.git/blob - images/signature.h
Implemented byte-bases trie.
[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 extern double image_sig_border_size;
9 extern int image_sig_border_bonus;
10 extern double image_sig_inertia_scale[];
11 extern double image_sig_textured_threshold;
12 extern int image_sig_compare_method;
13 extern uns image_sig_cmp_features_weights[];
14
15 #define IMAGE_VEC_F     6
16 #define IMAGE_REG_F     IMAGE_VEC_F
17 #define IMAGE_REG_H     5
18 #define IMAGE_REG_MAX   16
19
20 /* K-dimensional feature vector (6 bytes) */
21 struct image_vector {
22   byte f[IMAGE_VEC_F];          /* texture features */
23 } PACKED;
24
25 /* Features for image regions (16 bytes) */
26 struct image_region {
27   byte f[IMAGE_VEC_F];          /* texture features - L, u, v, LH, HL, HH */
28   byte h[IMAGE_REG_H];          /* shape/pos features - I1, I2, I3, X, Y */
29   byte wa;                      /* normalized area percentage */
30   byte wb;                      /* normalized weight */
31 };
32
33 #define IMAGE_SIG_TEXTURED      0x1
34
35 /* Image signature (usually 16 + len * 16 bytes) */
36 struct image_signature {
37   byte len;                     /* number of regions */
38   byte flags;                   /* IMAGE_SIG_xxx */
39   u16 cols;                     /* image width */
40   u16 rows;                     /* image height */
41   u16 df;                       /* average weighted f dist */
42   u16 dh;                       /* average weighted h dist */
43   struct image_vector vec;      /* average features of all regions... simple signature */
44   struct image_region reg[IMAGE_REG_MAX];/* feature vector for every region */
45 };
46
47 struct image_cluster {
48   union {
49     struct {
50       s32 dot;                  /* dot product of the splitting plane */
51       s8 vec[IMAGE_VEC_F];      /* normal vector of the splitting plane */
52     };
53     struct {
54       u64 pos;                  /* cluster size in bytes */
55     };
56   };
57 };
58
59 static inline uns
60 image_signature_size(uns len)
61 {
62   return OFFSETOF(struct image_signature, reg) + len * sizeof(struct image_region);
63 }
64
65 /* sig-dump.c */
66
67 #define IMAGE_VECTOR_DUMP_MAX (IMAGE_VEC_F * 16 + 1)
68 #define IMAGE_REGION_DUMP_MAX ((IMAGE_REG_F + IMAGE_REG_H) * 16 + 100)
69
70 byte *image_vector_dump(byte *buf, struct image_vector *vec);
71 byte *image_region_dump(byte *buf, struct image_region *reg);
72
73 struct image_sig_block {
74   struct image_sig_block *next;         /* linked list */
75   u32 x, y;                             /* block position */
76   byte area;                            /* block area in pixels (usually 16) */
77   byte region;                          /* region index */
78   byte v[IMAGE_VEC_F];                  /* feature vector */
79 };
80
81 struct image_sig_region {
82   struct image_sig_block *blocks;
83   u32 count;
84   u32 a[IMAGE_VEC_F];
85   u32 b[IMAGE_VEC_F];
86   u32 c[IMAGE_VEC_F];
87   u64 e;
88   u64 w_sum;
89 };
90
91 struct image_sig_data {
92   struct image *image;
93   struct image_sig_block *blocks;
94   struct image_sig_region regions[IMAGE_REG_MAX];
95   u32 cols;
96   u32 rows;
97   u32 full_cols;
98   u32 full_rows;
99   u32 flags;
100   u32 area;
101   u32 valid;
102   u32 blocks_count;
103   u32 regions_count;
104   u32 f[IMAGE_VEC_F];
105 };
106
107 /* sig-init.c */
108
109 int compute_image_signature(struct image_context *ctx, struct image_signature *sig, struct image *image);
110
111 int image_sig_init(struct image_context *ctx, struct image_sig_data *data, struct image *image);
112 void image_sig_preprocess(struct image_sig_data *data);
113 void image_sig_finish(struct image_sig_data *data, struct image_signature *sig);
114 void image_sig_cleanup(struct image_sig_data *data);
115
116 /* sig-seg.c */
117
118 void image_sig_segmentation(struct image_sig_data *data);
119
120 /* sig-txt.c */
121
122 void image_sig_detect_textured(struct image_sig_data *data);
123
124 /* sig-cmp.c */
125
126 uns image_signatures_dist(struct image_signature *sig1, struct image_signature *sig2);
127 uns image_signatures_dist_explain(struct image_signature *sig1, struct image_signature *sig2, void (*msg)(byte *text, void *param), void *param);
128
129 #endif
130