/** Compare the two template matcher implementations against one another */
  @Test
  public void compareTest() {
    for (TemplateMatcher.Mode sMode : TemplateMatcher.Mode.values()) {
      TemplateMatcher sMatcher = new TemplateMatcher(template, sMode);
      sMatcher.analyseImage(image);
      FValuePixel[] sBestResponses = sMatcher.getBestResponses(5);
      FImage sResponse = sMatcher.getResponseMap().normalise();

      FourierTemplateMatcher.Mode fMode = FourierTemplateMatcher.Mode.valueOf(sMode.toString());
      FourierTemplateMatcher fMatcher = new FourierTemplateMatcher(template, fMode);
      fMatcher.analyseImage(image);
      FValuePixel[] fBestResponses = fMatcher.getBestResponses(5);
      FImage fResponse = fMatcher.getResponseMap().normalise();

      System.out.println(sMode);

      assertEquals(fMode.scoresAscending(), sMode.scoresAscending());

      assertEquals(fBestResponses.length, sBestResponses.length);
      for (int i = 0; i < fBestResponses.length; i++) {
        assertEquals(fBestResponses[i].x, sBestResponses[i].x);
        assertEquals(fBestResponses[i].y, sBestResponses[i].y);
      }

      assertEquals(fResponse.width, sResponse.width);
      assertEquals(fResponse.height, sResponse.height);

      for (int y = 0; y < fResponse.height; y++) {
        for (int x = 0; x < fResponse.width; x++) {
          assertEquals(fResponse.pixels[y][x], sResponse.pixels[y][x], 0.15);
        }
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Testing
   *
   * @param args
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {
    FImage image = ImageUtilities.readF(new File("/Users/jsh2/Desktop/image.png"));
    FImage template = image.extractROI(100, 100, 100, 100);
    image.fill(0f);
    image.drawImage(template, 100, 100);

    TemplateMatcher matcher = new TemplateMatcher(template, Mode.CORRELATION);
    matcher.setSearchBounds(new Rectangle(100, 100, 200, 200));
    image.analyseWith(matcher);
    DisplayUtilities.display(matcher.responseMap.normalise());

    MBFImage cimg = image.toRGB();
    for (FValuePixel p : matcher.getBestResponses(10)) {
      System.out.println(p);
      cimg.drawPoint(p, RGBColour.RED, 1);
    }

    cimg.drawShape(matcher.getSearchBounds(), RGBColour.BLUE);
    cimg.drawShape(new Rectangle(100, 100, 100, 100), RGBColour.GREEN);

    DisplayUtilities.display(cimg);
  }