Example #1
0
      @Override
      public final float computeMatchScore(
          final float[][] img,
          final int x,
          final int y,
          final float[][] template,
          final int templateX,
          final int templateY,
          final int templateWidth,
          final int templateHeight) {
        float imgMean = MeanCenter.patchMean(img, x, y, templateWidth, templateHeight);
        float templateMean =
            MeanCenter.patchMean(template, templateX, templateY, templateWidth, templateHeight);

        return computeMatchScore(
            img,
            x,
            y,
            imgMean,
            template,
            templateX,
            templateY,
            templateWidth,
            templateHeight,
            templateMean);
      }
Example #2
0
      @Override
      protected final float computeMatchScore(
          final FImage image,
          final FImage template,
          final int x,
          final int y,
          final Object workingSpace) {
        final float[][] imageData = image.pixels;
        final float[][] templateData = template.pixels;

        final float templateMean = (Float) workingSpace;
        final float imgMean = MeanCenter.patchMean(imageData);

        return computeMatchScore(
            imageData,
            x,
            y,
            imgMean,
            templateData,
            0,
            0,
            template.width,
            template.height,
            templateMean);
      }
Example #3
0
      @Override
      public final float computeMatchScore(
          final float[][] img,
          final int x,
          final int y,
          final float[][] template,
          final int templateX,
          final int templateY,
          final int templateWidth,
          final int templateHeight) {
        float imgMean = MeanCenter.patchMean(img, x, y, templateWidth, templateHeight);
        float templateMean =
            MeanCenter.patchMean(template, templateX, templateY, templateWidth, templateHeight);

        final int stopX1 = templateWidth + x;
        final int stopY1 = templateHeight + y;
        final int stopX2 = templateWidth + templateX;
        final int stopY2 = templateHeight + templateY;

        float score = 0;
        float s1 = 0;
        float s2 = 0;

        for (int yy1 = y, yy2 = templateY; yy1 < stopY1 && yy2 < stopY2; yy1++, yy2++) {
          for (int xx1 = x, xx2 = templateX; xx1 < stopX1 && xx2 < stopX2; xx1++, xx2++) {
            float ival = (img[yy1][xx1] - imgMean);
            float tval = (template[yy2][xx2] - templateMean);

            float prod = (ival * tval);

            score += prod;

            s1 += (ival * ival);
            s2 += (tval * tval);
          }
        }

        double norm = Math.sqrt(s1 * s2);

        if (norm == 0) return 0;

        return (float) (score / norm);
      }
Example #4
0
      @Override
      protected final float computeMatchScore(
          final FImage image,
          final FImage template,
          final int x,
          final int y,
          final Object workingSpace) {
        final int width = template.width;
        final int height = template.height;

        float imgMean = MeanCenter.patchMean(image.pixels, x, y, width, height);

        float score = 0;
        float si = 0;
        final float st = (Float) workingSpace;

        final float[][] imageData = image.pixels;
        final float[][] templateData = template.pixels;

        for (int j = 0; j < height; j++) {
          for (int i = 0; i < width; i++) {
            float ival = imageData[j + y][i + x] - imgMean;

            float prod = (ival * templateData[j][i]);

            score += prod;

            si += (ival * ival);
          }
        }

        double norm = Math.sqrt(si * st);

        if (norm == 0) return 0;

        return (float) (score / norm);
      }
Example #5
0
 @Override
 public Float prepareWorkingSpace(FImage template) {
   return MeanCenter.patchMean(template.pixels);
 }