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