From 96e3044fbf43839aba9b498df3ec994e7c40dde8 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Sat, 16 Sep 2006 09:09:18 +0200 Subject: [PATCH] configurable weighted features distance --- cf/images | 4 ++++ images/config.c | 2 ++ images/sig-cmp-gen.h | 30 +++++++++++++++--------------- images/signature.h | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/cf/images b/cf/images index 83b05840..cd7f61ed 100644 --- a/cf/images +++ b/cf/images @@ -21,6 +21,10 @@ TexturedThreshold 0.32 CompareMethod 2 +# Array of multiplicative constants in feature vectors distance computation +# (L, u, v, LH, HL, HH, H0, H1, H2). Each one must be in range 0..15. +CompareFeaturesWeights 1 2 2 1 1 1 1 1 1 + } ######## Duplicates finder ###################################################### diff --git a/images/config.c b/images/config.c index 931cc199..a992dbb3 100644 --- a/images/config.c +++ b/images/config.c @@ -21,6 +21,7 @@ uns image_sig_postquant_max_steps; uns image_sig_postquant_threshold; double image_sig_textured_threshold; uns image_sig_compare_method; +uns image_sig_cmp_features_weights[IMAGE_VEC_F + IMAGE_REG_H]; static struct cf_section sig_config = { CF_ITEMS{ @@ -32,6 +33,7 @@ static struct cf_section sig_config = { CF_UNS("PostQuantThreshold", &image_sig_postquant_threshold), CF_DOUBLE("TexturedThreshold", &image_sig_textured_threshold), CF_UNS("CompareMethod", &image_sig_compare_method), + CF_UNS_ARY("CompareFeaturesWeights", image_sig_cmp_features_weights, IMAGE_VEC_F + IMAGE_REG_H), CF_END } }; diff --git a/images/sig-cmp-gen.h b/images/sig-cmp-gen.h index c6b80195..e6164d53 100644 --- a/images/sig-cmp-gen.h +++ b/images/sig-cmp-gen.h @@ -68,16 +68,16 @@ image_signatures_dist_2_explain(struct image_signature *sig1, struct image_signa for (i = 0, reg1 = sig1->reg; i < sig1->len; i++, reg1++) { uns ds = - isqr((int)reg1->h[0] - (int)reg2->h[0]) + - isqr((int)reg1->h[1] - (int)reg2->h[1]) + - isqr((int)reg1->h[2] - (int)reg2->h[2]); + image_sig_cmp_features_weights[6] * isqr((int)reg1->h[0] - (int)reg2->h[0]) + + image_sig_cmp_features_weights[7] * isqr((int)reg1->h[1] - (int)reg2->h[1]) + + image_sig_cmp_features_weights[8] * isqr((int)reg1->h[2] - (int)reg2->h[2]); uns dt = - isqr((int)reg1->f[0] - (int)reg2->f[0]) + - isqr((int)reg1->f[1] - (int)reg2->f[1]) + - isqr((int)reg1->f[2] - (int)reg2->f[2]) + - isqr((int)reg1->f[3] - (int)reg2->f[3]) + - isqr((int)reg1->f[4] - (int)reg2->f[4]) + - isqr((int)reg1->f[5] - (int)reg2->f[5]); + image_sig_cmp_features_weights[0] * isqr((int)reg1->f[0] - (int)reg2->f[0]) + + image_sig_cmp_features_weights[1] * isqr((int)reg1->f[1] - (int)reg2->f[1]) + + image_sig_cmp_features_weights[2] * isqr((int)reg1->f[2] - (int)reg2->f[2]) + + image_sig_cmp_features_weights[3] * isqr((int)reg1->f[3] - (int)reg2->f[3]) + + image_sig_cmp_features_weights[4] * isqr((int)reg1->f[4] - (int)reg2->f[4]) + + image_sig_cmp_features_weights[5] * isqr((int)reg1->f[5] - (int)reg2->f[5]); if (ds < 1000) dt *= 8; else if (ds < 10000) @@ -95,12 +95,12 @@ image_signatures_dist_2_explain(struct image_signature *sig1, struct image_signa for (i = 0, reg1 = sig1->reg; i < sig1->len; i++, reg1++) { uns dt = - isqr((int)reg1->f[0] - (int)reg2->f[0]) + - isqr((int)reg1->f[1] - (int)reg2->f[1]) + - isqr((int)reg1->f[2] - (int)reg2->f[2]) + - isqr((int)reg1->f[3] - (int)reg2->f[3]) + - isqr((int)reg1->f[4] - (int)reg2->f[4]) + - isqr((int)reg1->f[5] - (int)reg2->f[5]); + image_sig_cmp_features_weights[0] * isqr((int)reg1->f[0] - (int)reg2->f[0]) + + image_sig_cmp_features_weights[1] * isqr((int)reg1->f[1] - (int)reg2->f[1]) + + image_sig_cmp_features_weights[2] * isqr((int)reg1->f[2] - (int)reg2->f[2]) + + image_sig_cmp_features_weights[3] * isqr((int)reg1->f[3] - (int)reg2->f[3]) + + image_sig_cmp_features_weights[4] * isqr((int)reg1->f[4] - (int)reg2->f[4]) + + image_sig_cmp_features_weights[5] * isqr((int)reg1->f[5] - (int)reg2->f[5]); dist[n++] = (dt << 12) + i + (j << 4); DBG("[%u, %u] dt=%u", i, j, dt); MSG("[%u, %u] dt=%u", i, j, dt); diff --git a/images/signature.h b/images/signature.h index e84c7f31..2b93e32a 100644 --- a/images/signature.h +++ b/images/signature.h @@ -6,7 +6,7 @@ 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_textured_threshold; -extern uns image_sig_compare_method; +extern uns image_sig_compare_method, image_sig_cmp_features_weights[]; #define IMAGE_VEC_F 6 #define IMAGE_REG_F IMAGE_VEC_F -- 2.39.2