]> mj.ucw.cz Git - libucw.git/blob - images/signature.h
tableprinter&xtypes: assert changed to die in tests, fix of timestamp parsing
[libucw.git] / images / signature.h
1 #ifndef _IMAGES_SIGNATURE_H
2 #define _IMAGES_SIGNATURE_H
3
4 #ifdef CONFIG_UCW_CLEAN_ABI
5 #define compute_image_signature ucw_compute_image_signature
6 #define image_region_dump ucw_image_region_dump
7 #define image_sig_border_bonus ucw_image_sig_border_bonus
8 #define image_sig_border_size ucw_image_sig_border_size
9 #define image_sig_cleanup ucw_image_sig_cleanup
10 #define image_sig_cmp_features_weights ucw_image_sig_cmp_features_weights
11 #define image_sig_compare_method ucw_image_sig_compare_method
12 #define image_sig_detect_textured ucw_image_sig_detect_textured
13 #define image_sig_finish ucw_image_sig_finish
14 #define image_sig_inertia_scale ucw_image_sig_inertia_scale
15 #define image_sig_init ucw_image_sig_init
16 #define image_sig_min_height ucw_image_sig_min_height
17 #define image_sig_min_width ucw_image_sig_min_width
18 #define image_sig_postquant_max_steps ucw_image_sig_postquant_max_steps
19 #define image_sig_postquant_min_steps ucw_image_sig_postquant_min_steps
20 #define image_sig_postquant_threshold ucw_image_sig_postquant_threshold
21 #define image_sig_preprocess ucw_image_sig_preprocess
22 #define image_sig_prequant_thresholds ucw_image_sig_prequant_thresholds
23 #define image_sig_segmentation ucw_image_sig_segmentation
24 #define image_sig_textured_threshold ucw_image_sig_textured_threshold
25 #define image_signatures_dist ucw_image_signatures_dist
26 #define image_signatures_dist_explain ucw_image_signatures_dist_explain
27 #define image_vector_dump ucw_image_vector_dump
28 #endif
29
30 /* Configuration */
31 extern uint image_sig_min_width, image_sig_min_height;
32 extern uint *image_sig_prequant_thresholds;
33 extern uint image_sig_postquant_min_steps, image_sig_postquant_max_steps, image_sig_postquant_threshold;
34 extern double image_sig_border_size;
35 extern int image_sig_border_bonus;
36 extern double image_sig_inertia_scale[];
37 extern double image_sig_textured_threshold;
38 extern int image_sig_compare_method;
39 extern uint image_sig_cmp_features_weights[];
40
41 #define IMAGE_VEC_F     6
42 #define IMAGE_REG_F     IMAGE_VEC_F
43 #define IMAGE_REG_H     5
44 #define IMAGE_REG_MAX   16
45
46 /* K-dimensional feature vector (6 bytes) */
47 struct image_vector {
48   byte f[IMAGE_VEC_F];          /* texture features */
49 } PACKED;
50
51 /* Features for image regions (16 bytes) */
52 struct image_region {
53   byte f[IMAGE_VEC_F];          /* texture features - L, u, v, LH, HL, HH */
54   byte h[IMAGE_REG_H];          /* shape/pos features - I1, I2, I3, X, Y */
55   byte wa;                      /* normalized area percentage */
56   byte wb;                      /* normalized weight */
57 };
58
59 #define IMAGE_SIG_TEXTURED      0x1
60
61 /* Image signature (usually 16 + len * 16 bytes) */
62 struct image_signature {
63   byte len;                     /* number of regions */
64   byte flags;                   /* IMAGE_SIG_xxx */
65   u16 cols;                     /* image width */
66   u16 rows;                     /* image height */
67   u16 df;                       /* average weighted f dist */
68   u16 dh;                       /* average weighted h dist */
69   struct image_vector vec;      /* average features of all regions... simple signature */
70   struct image_region reg[IMAGE_REG_MAX];/* feature vector for every region */
71 };
72
73 struct image_cluster {
74   union {
75     struct {
76       s32 dot;                  /* dot product of the splitting plane */
77       s8 vec[IMAGE_VEC_F];      /* normal vector of the splitting plane */
78     };
79     struct {
80       u64 pos;                  /* cluster size in bytes */
81     };
82   };
83 };
84
85 static inline uint image_signature_size(uint len)
86 {
87   return OFFSETOF(struct image_signature, reg) + len * sizeof(struct image_region);
88 }
89
90 /* sig-dump.c */
91
92 #define IMAGE_VECTOR_DUMP_MAX (IMAGE_VEC_F * 16 + 1)
93 #define IMAGE_REGION_DUMP_MAX ((IMAGE_REG_F + IMAGE_REG_H) * 16 + 100)
94
95 byte *image_vector_dump(byte *buf, struct image_vector *vec);
96 byte *image_region_dump(byte *buf, struct image_region *reg);
97
98 struct image_sig_block {
99   struct image_sig_block *next;         /* linked list */
100   u32 x, y;                             /* block position */
101   byte area;                            /* block area in pixels (usually 16) */
102   byte region;                          /* region index */
103   byte v[IMAGE_VEC_F];                  /* feature vector */
104 };
105
106 struct image_sig_region {
107   struct image_sig_block *blocks;
108   u32 count;
109   u32 a[IMAGE_VEC_F];
110   u32 b[IMAGE_VEC_F];
111   u32 c[IMAGE_VEC_F];
112   u64 e;
113   u64 w_sum;
114 };
115
116 struct image_sig_data {
117   struct image *image;
118   struct image_sig_block *blocks;
119   struct image_sig_region regions[IMAGE_REG_MAX];
120   u32 cols;
121   u32 rows;
122   u32 full_cols;
123   u32 full_rows;
124   u32 flags;
125   u32 area;
126   u32 valid;
127   u32 blocks_count;
128   u32 regions_count;
129   u32 f[IMAGE_VEC_F];
130 };
131
132 /* sig-init.c */
133
134 int compute_image_signature(struct image_context *ctx, struct image_signature *sig, struct image *image);
135
136 int image_sig_init(struct image_context *ctx, struct image_sig_data *data, struct image *image);
137 void image_sig_preprocess(struct image_sig_data *data);
138 void image_sig_finish(struct image_sig_data *data, struct image_signature *sig);
139 void image_sig_cleanup(struct image_sig_data *data);
140
141 /* sig-seg.c */
142
143 void image_sig_segmentation(struct image_sig_data *data);
144
145 /* sig-txt.c */
146
147 void image_sig_detect_textured(struct image_sig_data *data);
148
149 /* sig-cmp.c */
150
151 uint image_signatures_dist(struct image_signature *sig1, struct image_signature *sig2);
152 uint image_signatures_dist_explain(struct image_signature *sig1, struct image_signature *sig2, void (*msg)(byte *text, void *param), void *param);
153
154 #endif
155