]> mj.ucw.cz Git - libucw.git/commitdiff
- experimenting with segmentation parameters
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Sun, 27 Aug 2006 11:41:28 +0000 (13:41 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Sun, 27 Aug 2006 11:41:28 +0000 (13:41 +0200)
- changed colliding image-sim-test parameter
- remove obsolete code

cf/images
images/image-sim-test.c
images/sig-init.c
images/signature.h

index e6c64fd1570b7bcd28a8e685b45bd395522d4d6e..7772e8587c2c4deee1a8954f4dd0ad31229775d5 100644 (file)
--- 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
index d83479969d9fdcc0a100094310a7cf4641425355..8116206fe8461c9ecb6dbad5f5e2d98d8cb58558 100644 (file)
@@ -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:
index 13f21fce57ad707cdf640a660431969a8b227550..5b0b33f9b4a8af32ca0ec0c7b63c7c493d5ebab1 100644 (file)
@@ -21,7 +21,7 @@
 #include <alloca.h>
 
 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 */
index 3511f914fbb728a2856562c9ab8c09ed8d3240af..aeb649673358db0e60495374962e3b1addca5678 100644 (file)
@@ -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