1 #ifndef _IMAGES_SIGNATURE_H
2 #define _IMAGES_SIGNATURE_H
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
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[];
42 #define IMAGE_REG_F IMAGE_VEC_F
44 #define IMAGE_REG_MAX 16
46 /* K-dimensional feature vector (6 bytes) */
48 byte f[IMAGE_VEC_F]; /* texture features */
51 /* Features for image regions (16 bytes) */
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 */
59 #define IMAGE_SIG_TEXTURED 0x1
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 */
73 struct image_cluster {
76 s32 dot; /* dot product of the splitting plane */
77 s8 vec[IMAGE_VEC_F]; /* normal vector of the splitting plane */
80 u64 pos; /* cluster size in bytes */
85 static inline uint image_signature_size(uint len)
87 return OFFSETOF(struct image_signature, reg) + len * sizeof(struct image_region);
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)
95 byte *image_vector_dump(byte *buf, struct image_vector *vec);
96 byte *image_region_dump(byte *buf, struct image_region *reg);
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 */
106 struct image_sig_region {
107 struct image_sig_block *blocks;
116 struct image_sig_data {
118 struct image_sig_block *blocks;
119 struct image_sig_region regions[IMAGE_REG_MAX];
134 int compute_image_signature(struct image_context *ctx, struct image_signature *sig, struct image *image);
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);
143 void image_sig_segmentation(struct image_sig_data *data);
147 void image_sig_detect_textured(struct image_sig_data *data);
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);