From 5f3de5acaf38874f0117f8cff31ad79e276ee289 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Sun, 27 Aug 2006 13:41:28 +0200 Subject: [PATCH] - experimenting with segmentation parameters - changed colliding image-sim-test parameter - remove obsolete code --- cf/images | 2 +- images/image-sim-test.c | 16 +++++++-------- images/sig-init.c | 23 +++++++++++++--------- images/signature.h | 43 ++++------------------------------------- 4 files changed, 27 insertions(+), 57 deletions(-) diff --git a/cf/images b/cf/images index e6c64fd1..7772e858 100644 --- a/cf/images +++ b/cf/images @@ -12,7 +12,7 @@ ImageSig { MinWidth 16 MinHeight 16 -PreQuantThresholds 9 9 25 25 100 100 400 400 1000 1000 10000 10000 10000 40000 40000 +PreQuantThresholds 9 100 1000 1000 2000 4000 8000 10000 10000 20000 20000 40000 40000 40000 40000 PostQuantMinSteps 2 PostQuantMaxSteps 10 PostQuantThreshold 2 diff --git a/images/image-sim-test.c b/images/image-sim-test.c index d8347996..8116206f 100644 --- a/images/image-sim-test.c +++ b/images/image-sim-test.c @@ -31,13 +31,13 @@ Usage: image-sim-test [options] image1 [image2] \n\ -f --format-1 image1 format (jpeg, gif, png)\n\ -F --format-2 image2 format\n\ -g --background background color (hexadecimal RRGGBB)\n\ --s --segmentation-1 writes image1 segmentation to given file\n\ --S --segmentation-2 writes image2 segmentation to given file\n\ +-r --segmentation-1 writes image1 segmentation to given file\n\ +-R --segmentation-2 writes image2 segmentation to given file\n\ ", stderr); exit(1); } -static char *shortopts = "qf:F:g:t:s:S:" CF_SHORT_OPTS; +static char *shortopts = "qf:F:g:t:r:R:" CF_SHORT_OPTS; static struct option longopts[] = { CF_LONG_OPTS @@ -45,8 +45,8 @@ static struct option longopts[] = { "format-1", 0, 0, 'f' }, { "format-2", 0, 0, 'F' }, { "background", 0, 0, 'g' }, - { "segmentation-1", 0, 0, 's' }, - { "segmentation-2", 0, 0, 'S' }, + { "segmentation-1", 0, 0, 'r' }, + { "segmentation-2", 0, 0, 'R' }, { NULL, 0, 0, 0 } }; @@ -92,7 +92,7 @@ write_segmentation(struct image_sig_data *data, byte *fn) { byte c[3]; double luv[3], xyz[3], srgb[3]; - luv[0] = data->regions[i].a[0] * (2 / 2.55); + luv[0] = data->regions[i].a[0] * (4 / 2.55); luv[1] = ((int)data->regions[i].a[1] - 128) * (4 / 2.55); luv[2] = ((int)data->regions[i].a[2] - 128) * (4 / 2.55); luv_to_xyz_slow(xyz, luv); @@ -161,10 +161,10 @@ main(int argc, char **argv) color_make_rgb(&background_color, (v >> 16) & 255, (v >> 8) & 255, v & 255); } break; - case 's': + case 'r': segmentation_name_1 = optarg; break; - case 'S': + case 'R': segmentation_name_2 = optarg; break; default: diff --git a/images/sig-init.c b/images/sig-init.c index 13f21fce..5b0b33f9 100644 --- a/images/sig-init.c +++ b/images/sig-init.c @@ -21,7 +21,7 @@ #include int -image_sig_init(struct image_thread *thread UNUSED, struct image_sig_data *data, struct image *image) +image_sig_init(struct image_thread *thread, struct image_sig_data *data, struct image *image) { ASSERT((image->flags & IMAGE_PIXEL_FORMAT) == COLOR_SPACE_RGB); data->image = image; @@ -30,6 +30,11 @@ image_sig_init(struct image_thread *thread UNUSED, struct image_sig_data *data, data->full_cols = image->cols >> 2; data->full_rows = image->rows >> 2; data->blocks_count = data->cols * data->rows; + if (data->blocks_count >= 0x10000) + { + image_thread_err(thread, IMAGE_ERR_INVALID_DIMENSIONS, "Image too large for implemented signature algorithm."); + return 0; + } data->blocks = xmalloc(data->blocks_count * sizeof(struct image_sig_block)); data->area = image->cols * image->rows; DBG("Computing signature for image of %ux%u pixels (%ux%u blocks)", @@ -66,7 +71,7 @@ image_sig_preprocess(struct image_sig_data *data) { byte luv[3]; srgb_to_luv_pixel(luv, p2); - l_sum += *tp++ = luv[0] / 2; + l_sum += *tp++ = luv[0] / 4; u_sum += luv[1]; v_sum += luv[2]; } @@ -91,7 +96,7 @@ image_sig_preprocess(struct image_sig_data *data) { byte luv[3]; srgb_to_luv_pixel(luv, p3); - l_sum += *tp++ = luv[0] / 2; + l_sum += *tp++ = luv[0] / 4; u_sum += luv[1]; v_sum += luv[2]; } @@ -137,15 +142,15 @@ image_sig_preprocess(struct image_sig_data *data) /* ... and to the columns... skip LL band */ for (i = 0; i < 2; i++) { - t[i + 8] = (DAUB_3 * s[i + 8] - DAUB_2 * s[i +12] + DAUB_1 * s[i + 0] - DAUB_0 * s[i + 4]) / 0x4000; - t[i +12] = (DAUB_3 * s[i + 0] - DAUB_2 * s[i + 4] + DAUB_1 * s[i + 8] - DAUB_0 * s[i +12]) / 0x4000; + t[i + 8] = (DAUB_3 * s[i + 8] - DAUB_2 * s[i +12] + DAUB_1 * s[i + 0] - DAUB_0 * s[i + 4]) / 0x10000; + t[i +12] = (DAUB_3 * s[i + 0] - DAUB_2 * s[i + 4] + DAUB_1 * s[i + 8] - DAUB_0 * s[i +12]) / 0x10000; } for (; i < 4; i++) { - t[i + 0] = (DAUB_0 * s[i + 8] + DAUB_1 * s[i +12] + DAUB_2 * s[i + 0] + DAUB_3 * s[i + 4]) / 0x4000; - t[i + 4] = (DAUB_0 * s[i + 0] + DAUB_1 * s[i + 4] + DAUB_2 * s[i + 8] + DAUB_3 * s[i +12]) / 0x4000; - t[i + 8] = (DAUB_3 * s[i + 8] - DAUB_2 * s[i +12] + DAUB_1 * s[i + 0] - DAUB_0 * s[i + 4]) / 0x4000; - t[i +12] = (DAUB_3 * s[i + 0] - DAUB_2 * s[i + 4] + DAUB_1 * s[i + 8] - DAUB_0 * s[i +12]) / 0x4000; + t[i + 0] = (DAUB_0 * s[i + 8] + DAUB_1 * s[i +12] + DAUB_2 * s[i + 0] + DAUB_3 * s[i + 4]) / 0x10000; + t[i + 4] = (DAUB_0 * s[i + 0] + DAUB_1 * s[i + 4] + DAUB_2 * s[i + 8] + DAUB_3 * s[i +12]) / 0x10000; + t[i + 8] = (DAUB_3 * s[i + 8] - DAUB_2 * s[i +12] + DAUB_1 * s[i + 0] - DAUB_0 * s[i + 4]) / 0x10000; + t[i +12] = (DAUB_3 * s[i + 0] - DAUB_2 * s[i + 4] + DAUB_1 * s[i + 8] - DAUB_0 * s[i +12]) / 0x10000; } /* Extract energies in LH, HL and HH bands */ diff --git a/images/signature.h b/images/signature.h index 3511f914..aeb64967 100644 --- a/images/signature.h +++ b/images/signature.h @@ -48,10 +48,10 @@ byte *image_vector_dump(byte *buf, struct image_vector *vec); byte *image_region_dump(byte *buf, struct image_region *reg); struct image_sig_block { - struct image_sig_block *next; - u32 area; /* block area in pixels (usually 16) */ - u32 v[IMAGE_VEC_F]; - u32 x, y; /* block position */ + struct image_sig_block *next; /* linked list */ + u32 x, y; /* block position */ + byte area; /* block area in pixels (usually 16) */ + byte v[IMAGE_VEC_F]; /* feature vector */ }; struct image_sig_region { @@ -98,40 +98,5 @@ void image_sig_segmentation(struct image_sig_data *data); uns image_signatures_dist(struct image_signature *sig1, struct image_signature *sig2); -#if 0 -/* K-dimensional interval */ -struct image_bbox { - struct image_vector vec[2]; -}; - -/* 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 */ -}; - -/* 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; -}; - -/* 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; -}; - -#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 - #endif -- 2.39.5