public void compareToNaive(GrayS16 derivX, GrayS16 derivY) {
    GrayF32 expected = new GrayF32(derivX.width, derivX.height);
    GrayF32 found = new GrayF32(derivX.width, derivX.height);

    ImplSsdCornerNaive naive = new ImplSsdCornerNaive(width, height, 3, true);
    naive.process(derivX, derivY, expected);

    ImplShiTomasiCornerWeighted_S16 fast = new ImplShiTomasiCornerWeighted_S16(3);
    fast.process(derivX, derivY, found);

    // how the weighted is applied is different between these two verisons, which is why the error
    // tolerance is so high
    BoofTesting.assertEqualsInner(expected, found, 0.5, 3, 3, true);
  }
예제 #2
0
  public static void assertEqualsInner(
      ImageBase imgA, ImageBase imgB, double tol, int borderX, int borderY, boolean relative) {

    // if no specialized check exists, use a slower generalized approach
    if (imgA instanceof ImageSingleBand) {
      GImageSingleBand a = FactoryGImageSingleBand.wrap((ImageSingleBand) imgA);
      GImageSingleBand b = FactoryGImageSingleBand.wrap((ImageSingleBand) imgB);

      for (int y = borderY; y < imgA.height - borderY; y++) {
        for (int x = borderX; x < imgA.width - borderX; x++) {
          double valA = a.get(x, y).doubleValue();
          double valB = b.get(x, y).doubleValue();

          double error = Math.abs(valA - valB);
          if (relative) {
            double denominator = Math.abs(valA) + Math.abs(valB);
            if (denominator == 0) denominator = 1;
            error /= denominator;
          }
          if (error > tol)
            throw new RuntimeException(
                "Values not equal at (" + x + "," + y + ") " + valA + "  " + valB);
        }
      }
    } else if (imgA instanceof MultiSpectral) {
      MultiSpectral a = (MultiSpectral) imgA;
      MultiSpectral b = (MultiSpectral) imgB;

      if (a.getNumBands() != b.getNumBands())
        throw new RuntimeException("Number of bands not equal");

      for (int band = 0; band < a.getNumBands(); band++) {
        assertEqualsInner(a.getBand(band), b.getBand(band), tol, borderX, borderY, relative);
      }
    } else {
      throw new RuntimeException("Unknown image type");
    }
  }