]> mj.ucw.cz Git - libucw.git/blobdiff - images/sig-cmp.c
image segmentation moved to a new file
[libucw.git] / images / sig-cmp.c
index d5d3fb71a89924b72c7a10652726ce773ebb2492..ec3f1e865303beac7c058ef1bf262976e97493f7 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "lib/lib.h"
 #include "lib/math.h"
+#include "images/math.h"
 #include "images/images.h"
 #include "images/signature.h"
 #include <stdio.h>
@@ -30,7 +31,7 @@ image_signatures_dist(struct image_signature *sig1, struct image_signature *sig2
 
   /* Compute distance matrix */
   for (uns i = 0; i < cnt1; i++)
-    for (uns j = i + 1; j < cnt2; j++)
+    for (uns j = 0; j < cnt2; j++)
       {
        uns d = 0;
        for (uns k = 0; k < IMAGE_REG_F; k++)
@@ -57,8 +58,8 @@ image_signatures_dist(struct image_signature *sig1, struct image_signature *sig2
          f = MIN(f, mf[i][j]);
          h = MIN(h, mh[i][j]);
        }
-      lf[i] = (df * 0x10000) / (df + (int)sqrt(f));
-      lh[i] = (dh * 0x10000) / (dh + (int)sqrt(h));
+      lf[i] = (df * 0x10000) / (df + fast_sqrt_u32(f));
+      lh[i] = (dh * 0x10000) / (dh + fast_sqrt_u32(h));
       lfs += lf[i] * (6 * reg1[i].wa + 2 * reg1[i].wb);
       lhs += lh[i] * reg1[i].wa;
     }
@@ -70,8 +71,8 @@ image_signatures_dist(struct image_signature *sig1, struct image_signature *sig2
          f = MIN(f, mf[j][i]);
          h = MIN(h, mh[j][i]);
        }
-      lf[i + cnt1] = (df * 0x10000) / (df + (int)sqrt(f));
-      lh[i + cnt1] = (dh * 0x10000) / (dh + (int)sqrt(h));
+      lf[i + cnt1] = (df * 0x10000) / (df + fast_sqrt_u32(f));
+      lh[i + cnt1] = (dh * 0x10000) / (dh + fast_sqrt_u32(h));
       lfs += lf[i] * (6 * reg2[i].wa + 2 * reg2[i].wb);
       lhs += lh[i] * reg2[i].wa;
     }
@@ -107,5 +108,5 @@ image_signatures_dist(struct image_signature *sig1, struct image_signature *sig2
   DBG("measure=%.4f", measure / (double)(1 << (3 + 3 + 8 + 16)));
 #endif
 
-  return measure;
+  return (1 << (3 + 3 + 8 + 16)) - measure;
 }