]> mj.ucw.cz Git - libucw.git/blobdiff - images/signature.h
Conf: Rewritten configuration parser to support multiple contexts (step 1)
[libucw.git] / images / signature.h
index 2c2ab1013520c7d7ed90220171d3f704cacf0b7e..204174768a83c3e0ed22a276691afe5e9d22ccb2 100644 (file)
@@ -1,33 +1,67 @@
 #ifndef _IMAGES_SIGNATURE_H
 #define _IMAGES_SIGNATURE_H
 
+/* Configuration */
+extern uns image_sig_min_width, image_sig_min_height;
+extern uns *image_sig_prequant_thresholds;
+extern uns image_sig_postquant_min_steps, image_sig_postquant_max_steps, image_sig_postquant_threshold;
+extern double image_sig_border_size;
+extern int image_sig_border_bonus;
+extern double image_sig_inertia_scale[];
+extern double image_sig_textured_threshold;
+extern int image_sig_compare_method;
+extern uns image_sig_cmp_features_weights[];
+
 #define IMAGE_VEC_F    6
 #define IMAGE_REG_F    IMAGE_VEC_F
-#define IMAGE_REG_H    3
-#define IMAGE_REG_MAX  8
+#define IMAGE_REG_H    5
+#define IMAGE_REG_MAX  16
 
-/* K-dimensional feature vector */
+/* K-dimensional feature vector (6 bytes) */
 struct image_vector {
   byte f[IMAGE_VEC_F];         /* texture features */
 } PACKED;
 
-/* Fetures for image regions */
+/* Features for image regions (16 bytes) */
 struct image_region {
-  byte f[IMAGE_VEC_F];         /* texture features */
-  u16 h[IMAGE_REG_H];          /* shape features */
+  byte f[IMAGE_VEC_F];         /* texture features - L, u, v, LH, HL, HH */
+  byte h[IMAGE_REG_H];         /* shape/pos features - I1, I2, I3, X, Y */
   byte wa;                     /* normalized area percentage */
   byte wb;                     /* normalized weight */
-} PACKED;
+};
+
+#define IMAGE_SIG_TEXTURED     0x1
 
-/* Image signature */
+/* Image signature (usually 16 + len * 16 bytes) */
 struct image_signature {
-  struct image_vector vec;     /* Combination of all regions... simple signature */
-  byte len;                    /* Number of regions */
-  byte df;                     /* average f dist */
-  u16 dh;                      /* average h dist */
-  struct image_region reg[IMAGE_REG_MAX];/* Feature vector for every region */
+  byte len;                    /* number of regions */
+  byte flags;                  /* IMAGE_SIG_xxx */
+  u16 cols;                    /* image width */
+  u16 rows;                    /* image height */
+  u16 df;                      /* average weighted f dist */
+  u16 dh;                      /* average weighted h dist */
+  struct image_vector vec;     /* average features of all regions... simple signature */
+  struct image_region reg[IMAGE_REG_MAX];/* feature vector for every region */
+};
+
+struct image_cluster {
+  union {
+    struct {
+      s32 dot;                 /* dot product of the splitting plane */
+      s8 vec[IMAGE_VEC_F];     /* normal vector of the splitting plane */
+    };
+    struct {
+      u64 pos;                 /* cluster size in bytes */
+    };
+  };
 };
 
+static inline uns
+image_signature_size(uns len)
+{
+  return OFFSETOF(struct image_signature, reg) + len * sizeof(struct image_region);
+}
+
 /* sig-dump.c */
 
 #define IMAGE_VECTOR_DUMP_MAX (IMAGE_VEC_F * 16 + 1)
@@ -36,52 +70,61 @@ struct image_signature {
 byte *image_vector_dump(byte *buf, struct image_vector *vec);
 byte *image_region_dump(byte *buf, struct image_region *reg);
 
-/* sig-init.c */
+struct image_sig_block {
+  struct image_sig_block *next;                /* linked list */
+  u32 x, y;                            /* block position */
+  byte area;                           /* block area in pixels (usually 16) */
+  byte region;                         /* region index */
+  byte v[IMAGE_VEC_F];                 /* feature vector */
+};
 
-void bget_image_signature(struct fastbuf *fb, struct image_signature *sig);
-void bput_image_signature(struct fastbuf *fb, struct image_signature *sig);
-int compute_image_signature(struct image_thread *thread, struct image_signature *sig, struct image *image);
+struct image_sig_region {
+  struct image_sig_block *blocks;
+  u32 count;
+  u32 a[IMAGE_VEC_F];
+  u32 b[IMAGE_VEC_F];
+  u32 c[IMAGE_VEC_F];
+  u64 e;
+  u64 w_sum;
+};
 
-/* sig-cmp.c */
+struct image_sig_data {
+  struct image *image;
+  struct image_sig_block *blocks;
+  struct image_sig_region regions[IMAGE_REG_MAX];
+  u32 cols;
+  u32 rows;
+  u32 full_cols;
+  u32 full_rows;
+  u32 flags;
+  u32 area;
+  u32 valid;
+  u32 blocks_count;
+  u32 regions_count;
+  u32 f[IMAGE_VEC_F];
+};
 
-#define IMAGE_SIG_DIST_SCALE (3 + 3 + 8 + 16)
+/* sig-init.c */
 
-uns image_signatures_dist(struct image_signature *sig1, struct image_signature *sig2);
+int compute_image_signature(struct image_context *ctx, struct image_signature *sig, struct image *image);
 
-#if 0
-/* K-dimensional interval */
-struct image_bbox {
-  struct image_vector vec[2];
-};
+int image_sig_init(struct image_context *ctx, struct image_sig_data *data, struct image *image);
+void image_sig_preprocess(struct image_sig_data *data);
+void image_sig_finish(struct image_sig_data *data, struct image_signature *sig);
+void image_sig_cleanup(struct image_sig_data *data);
 
-/* Similarity search tree... will be changed */
-struct image_tree {
-  uns count;                   /* Number of images in the tree */
-  uns depth;                   /* Tree depth */
-  struct image_bbox bbox;      /* Bounding box containing all the */
-  struct image_node *nodes;    /* Internal nodes */
-  struct image_leaf *leaves;   /* Leaves */
-};
+/* sig-seg.c */
 
-/* Internal node in the search tree */
-#define IMAGE_NODE_LEAF                0x80000000              /* Node contains pointer to leaves array */
-#define IMAGE_NODE_DIM         0xff                    /* Split dimension */
-struct image_node {
-  u32 val;
-};
+void image_sig_segmentation(struct image_sig_data *data);
 
-/* Leaves in the search tree */
-#define IMAGE_LEAF_LAST                0x80000000              /* Last entry in the list */
-#define IMAGE_LEAF_BITS(i)     (31 / IMAGE_VEC_K)      /* Number of bits for relative position in i-th dimension */
-struct image_leaf {
-  u32 flags;           /* Relative position in bbox and last node flag */ 
-  oid_t oid;
-};
+/* sig-txt.c */
 
-#define stk_print_image_vector(v) ({ struct image_vector *_v = v; \
-    byte *_s = (byte *) alloca(IMAGE_VEC_K * 6), *_p = _s + sprintf(_s, "%d", _v->f[0]); \
-    for (uns _i = 1; _i < IMAGE_VEC_K; _i++) _p += sprintf(_p, " %d", _v->f[_i]); _s; })
-#endif
+void image_sig_detect_textured(struct image_sig_data *data);
+
+/* sig-cmp.c */
+
+uns image_signatures_dist(struct image_signature *sig1, struct image_signature *sig2);
+uns image_signatures_dist_explain(struct image_signature *sig1, struct image_signature *sig2, void (*msg)(byte *text, void *param), void *param);
 
 #endif