예제 #1
0
  @Test
  public void checkNeighbors() {
    int r = 3;
    Dummy alg = new Dummy(r, 2, 200, ImageUInt8.class);

    alg.scores = new float[20 * 30];
    ImageFlow flows = new ImageFlow(20, 30);
    ImageFlow.D tmp = new ImageFlow.D();

    tmp.valid = true;
    tmp.x = -1;
    tmp.y = 2;

    // checks to see if a pixel is invalid that it's flow is always set
    // if a pixel is valid then the score is only set if the score is better
    flows.get(6, 5).valid = true;
    alg.scores[5 * 20 + 6] = 10;
    flows.get(5, 5).valid = true;
    alg.scores[5 * 20 + 5] = 4;
    // same score, but more motion
    flows.get(5, 6).valid = true;
    alg.scores[6 * 20 + 5] = 5;
    flows.get(5, 6).x = 2;
    flows.get(5, 6).y = 2;
    // same score, but less motion
    flows.get(6, 6).valid = true;
    alg.scores[6 * 20 + 6] = 5;
    flows.get(6, 6).x = 0;
    flows.get(6, 6).y = 1;

    alg.checkNeighbors(6, 7, tmp, flows, 5);

    for (int i = -r; i <= r; i++) {
      for (int j = -r; j <= r; j++) {
        int x = j + 6;
        int y = i + 7;

        ImageFlow.D f = flows.get(x, y);

        assertTrue(f.valid);
        if (x == 5 && y == 5) {
          assertEquals(4, alg.scores[y * 20 + x], 1e-4);
          assertEquals(0, f.x, 1e-4);
          assertEquals(0, f.y, 1e-4);
        } else if (x == 6 && y == 6) {
          assertEquals(5, alg.scores[y * 20 + x], 1e-4);
          assertEquals(0, f.x, 1e-4);
          assertEquals(1, f.y, 1e-4);
        } else {
          assertEquals(x + " " + y, 5, alg.scores[y * 20 + x], 1e-4);
          assertEquals(-1, f.x, 1e-4);
          assertEquals(2, f.y, 1e-4);
        }
      }
    }
  }