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