Пример #1
0
  @Test
  public void testCrossNeighborhoodProduct() {

    Img<DoubleType> inputImg = makeInputImage();

    /* old way
    DiscreteNeigh neigh = new DiscreteNeigh(new long[2], new long[]{1,1}, new long[]{1,1});
    Condition<long[]> condition = new OnTheXYCrossCondition();
    Function<long[],DoubleType> input = new RealImageFunction<DoubleType,DoubleType>(inputImg, new DoubleType());
    Function<long[],DoubleType> one = new ConstantRealFunction<long[],DoubleType>(inputImg.firstElement(),1);
    Function<long[],DoubleType> conditionalFunc = new ConditionalFunction<long[],DoubleType>(condition, input, one);
    Function<long[],DoubleType> prodFunc = new RealProductFunction<DoubleType>(conditionalFunc);
    long[] index = new long[2];
    DoubleType output = new DoubleType();
    for (int x = 1; x < XSIZE-1; x++) {
    	for (int y = 1; y < YSIZE-1; y++) {
    		index[0] = x;
    		index[1] = y;
    		neigh.moveTo(index);
    		prodFunc.evaluate(neigh, neigh.getKeyPoint(), output);
    		//{
    		//	System.out.println(" FAILURE at ("+x+","+y+"): expected ("
    		//		+expectedValue(x,y)+") actual ("+output.getRealDouble()+")");
    		//	success = false;
    		//}
    		assertTrue(veryClose(output.getRealDouble(), expectedValue(x,y)));
    	}
    }
    */

    ArrayList<long[]> pts = new ArrayList<long[]>();
    pts.add(new long[] {-1, -1});
    pts.add(new long[] {-1, 1});
    pts.add(new long[] {0, 0});
    pts.add(new long[] {1, -1});
    pts.add(new long[] {1, 1});
    GeneralPointSet neigh = new GeneralPointSet(new long[] {0, 0}, pts);
    Function<long[], DoubleType> input =
        new RealImageFunction<DoubleType, DoubleType>(inputImg, new DoubleType());
    Function<PointSet, DoubleType> prodFunc = new RealProductFunction<DoubleType>(input);
    HyperVolumePointSet space =
        new HyperVolumePointSet(new long[] {1, 1}, new long[] {XSIZE - 2, YSIZE - 2});
    PointSetInputIterator iter = new PointSetInputIterator(space, neigh);
    DoubleType output = new DoubleType();
    PointSet points = null;
    while (iter.hasNext()) {
      points = iter.next(points);
      prodFunc.compute(points, output);
      int x = (int) points.getOrigin()[0];
      int y = (int) points.getOrigin()[1];
      // {
      //	System.out.println(" Point ("+x+","+y+"): expected ("
      //		+expectedValue(x,y)+") actual ("+output.getRealDouble()+")");
      //	success = false;
      // }
      assertTrue(veryClose(output.getRealDouble(), expectedValue(x, y)));
    }
  }
 private double measure(final Function<PointSet, DoubleType> func, final PointSet region) {
   final DoubleType output = new DoubleType();
   func.compute(region, output);
   return output.getRealDouble();
 }