예제 #1
0
  @Test
  public void elementMultConjB() {
    InterleavedF64 a = new InterleavedF64(width, height, 2);
    InterleavedF64 b = new InterleavedF64(width, height, 2);
    InterleavedF64 c = new InterleavedF64(width, height, 2);

    ImageMiscOps.fillUniform(a, rand, -10, 10);
    ImageMiscOps.fillUniform(b, rand, -10, 10);
    ImageMiscOps.fillUniform(c, rand, -10, 10);

    CirculantTracker.elementMultConjB(a, b, c);

    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        Complex64F aa = new Complex64F(a.getBand(x, y, 0), a.getBand(x, y, 1));
        Complex64F bb = new Complex64F(b.getBand(x, y, 0), b.getBand(x, y, 1));

        Complex64F cc = new Complex64F();
        ComplexMath64F.conj(bb, bb);
        ComplexMath64F.mult(aa, bb, cc);

        double foundReal = c.getBand(x, y, 0);
        double foundImg = c.getBand(x, y, 1);

        assertEquals(cc.real, foundReal, 1e-4);
        assertEquals(cc.imaginary, foundImg, 1e-4);
      }
    }
  }
예제 #2
0
  @Test
  public void computeAlphas() {
    InterleavedF64 yf = new InterleavedF64(width, height, 2);
    InterleavedF64 kf = new InterleavedF64(width, height, 2);
    InterleavedF64 alphaf = new InterleavedF64(width, height, 2);

    ImageMiscOps.fillUniform(yf, rand, -10, 10);
    ImageMiscOps.fillUniform(kf, rand, -10, 10);
    ImageMiscOps.fillUniform(alphaf, rand, -10, 10);

    float lambda = 0.01f;
    CirculantTracker.computeAlphas(yf, kf, lambda, alphaf);

    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        Complex64F a = new Complex64F(yf.getBand(x, y, 0), yf.getBand(x, y, 1));
        Complex64F b = new Complex64F(kf.getBand(x, y, 0) + lambda, kf.getBand(x, y, 1));

        Complex64F c = new Complex64F();
        ComplexMath64F.div(a, b, c);

        double foundReal = alphaf.getBand(x, y, 0);
        double foundImg = alphaf.getBand(x, y, 1);

        assertEquals(c.real, foundReal, 1e-4);
        assertEquals(c.imaginary, foundImg, 1e-4);
      }
    }
  }
  public BenchmarkConvolveNormalizeEdge() {
    imgInt8 = new ImageUInt8(imgWidth, imgHeight);
    imgInt16 = new ImageSInt16(imgWidth, imgHeight);
    out_I32 = new ImageSInt32(imgWidth, imgHeight);
    out_I16 = new ImageSInt16(imgWidth, imgHeight);
    out_I8 = new ImageUInt8(imgWidth, imgHeight);
    imgFloat32 = new ImageFloat32(imgWidth, imgHeight);
    out_F32 = new ImageFloat32(imgWidth, imgHeight);

    Random rand = new Random(234234);
    ImageMiscOps.fillUniform(imgInt8, rand, 0, 100);
    ImageMiscOps.fillUniform(imgInt16, rand, 0, 200);
    ImageMiscOps.fillUniform(imgFloat32, rand, 0, 200);
  }
  protected void checkMotion(double tranX, double tranY, double rot) {
    ImageUInt8 frame0 = new ImageUInt8(320, 240);
    ImageUInt8 frame1 = new ImageUInt8(320, 240);
    ImageMiscOps.fillUniform(frame0, rand, 0, 256);

    double c = Math.cos(rot);
    double s = Math.sin(rot);

    DistortImageOps.affine(frame0, frame1, TypeInterpolate.BILINEAR, c, -s, s, c, tranX, tranY);

    SfotConfig config = new SfotConfig();

    ImageGradient<ImageUInt8, ImageSInt16> gradient =
        FactoryDerivative.sobel(ImageUInt8.class, ImageSInt16.class);

    SparseFlowObjectTracker<ImageUInt8, ImageSInt16> alg =
        new SparseFlowObjectTracker<ImageUInt8, ImageSInt16>(
            config, ImageUInt8.class, ImageSInt16.class, gradient);

    RectangleRotate_F64 region0 = new RectangleRotate_F64(120, 140, 30, 40, 0.1);
    RectangleRotate_F64 region1 = new RectangleRotate_F64();

    alg.init(frame0, region0);
    assertTrue(alg.update(frame1, region1));

    double expectedX = c * region0.cx - s * region0.cy + tranX;
    double expectedY = s * region0.cx + c * region0.cy + tranY;
    double expectedYaw = UtilAngle.bound(region0.theta + rot);

    assertEquals(expectedX, region1.cx, 0.5);
    assertEquals(expectedY, region1.cy, 0.5);
    assertEquals(expectedYaw, region1.theta, 0.01);
  }
  /**
   * Creates a random image and looks for corners in it. Sees if the naive and fast algorithm
   * produce exactly the same results.
   */
  @Test
  public void compareToNaive() {
    GrayU8 img = new GrayU8(width, height);
    ImageMiscOps.fillUniform(img, new Random(0xfeed), 0, 100);

    GrayS16 derivX = new GrayS16(img.getWidth(), img.getHeight());
    GrayS16 derivY = new GrayS16(img.getWidth(), img.getHeight());

    GradientSobel.process(img, derivX, derivY, new ImageBorder1D_S32(BorderIndex1D_Extend.class));

    BoofTesting.checkSubImage(this, "compareToNaive", true, derivX, derivY);
  }
예제 #6
0
  private void setTargetLocation(int x, int y) {
    ImageMiscOps.fillUniform(image, rand, 0, 1);
    ImageMiscOps.fillRectangle(image, 100, cornerX, cornerY, 20, 20);
    pyramid.process(image);

    for (int i = 0; i < pyramid.getNumLayers(); i++) {
      GradientSobel.process(
          pyramid.getLayer(i),
          derivX[i],
          derivY[i],
          new ImageBorder1D_F32(BorderIndex1D_Extend.class));
    }
  }
예제 #7
0
  @Test
  public void imageDotProduct() {
    ImageFloat64 a = new ImageFloat64(width, height);
    ImageMiscOps.fillUniform(a, rand, 0, 10);

    double total = 0;
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        total += a.get(x, y) * a.get(x, y);
      }
    }
    double found = CirculantTracker.imageDotProduct(a);
    assertEquals(total, found, 1e-8);
  }
예제 #8
0
  @Test
  public void compareToConvolve_I8() throws NoSuchMethodException {
    CompareDerivativeToConvolution validator = new CompareDerivativeToConvolution();
    validator.setTarget(
        HessianThree_Standard.class.getMethod(
            "process", ImageUInt8.class, ImageSInt16.class, ImageSInt16.class, ImageSInt16.class));

    validator.setKernel(0, HessianThree.kernelXXYY_I32, true);
    validator.setKernel(1, HessianThree.kernelXXYY_I32, false);
    validator.setKernel(2, HessianThree.kernelCross_I32);

    ImageUInt8 input = new ImageUInt8(width, height);
    ImageMiscOps.fillUniform(input, rand, 0, 10);
    ImageSInt16 derivXX = new ImageSInt16(width, height);
    ImageSInt16 derivYY = new ImageSInt16(width, height);
    ImageSInt16 derivXY = new ImageSInt16(width, height);

    validator.compare(false, input, derivXX, derivYY, derivXY);
  }
예제 #9
0
  @Test
  public void compareToConvolve_F32() throws NoSuchMethodException {
    CompareDerivativeToConvolution validator = new CompareDerivativeToConvolution();
    validator.setTarget(
        GradientPrewitt.class.getMethod(
            "process",
            ImageFloat32.class,
            ImageFloat32.class,
            ImageFloat32.class,
            ImageBorder_F32.class));

    validator.setKernel(0, GradientPrewitt.kernelDerivX_F32);
    validator.setKernel(1, GradientPrewitt.kernelDerivY_F32);

    ImageFloat32 input = new ImageFloat32(width, height);
    ImageMiscOps.fillUniform(input, rand, 0, 10);
    ImageFloat32 derivX = new ImageFloat32(width, height);
    ImageFloat32 derivY = new ImageFloat32(width, height);

    validator.compare(input, derivX, derivY);
  }