Ejemplo n.º 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)));
    }
  }
Ejemplo n.º 2
0
  /** Tests {@link OpService#run(Op, Object...)}. */
  @Test
  public void testRunByOp() {
    final DoubleType value = new DoubleType(123.456);

    assertFalse(Double.isInfinite(value.get()));
    final Object result = ops.run(new InfinityOp(), value);
    assertSame(value, result);
    assertTrue(Double.isInfinite(value.get()));
  }
Ejemplo n.º 3
0
  /** Tests {@link OpService#op(String, Object...)}. */
  @Test
  public void testOpByName() {
    final DoubleType value = new DoubleType(123.456);

    final Op op = ops.op("test.infinity", value);
    assertSame(InfinityOp.class, op.getClass());

    assertFalse(Double.isInfinite(value.get()));
    op.run();
    assertTrue(Double.isInfinite(value.get()));
  }
Ejemplo n.º 4
0
  /** Tests {@link OpService#module(Class, Object...)}. */
  @Test
  public void testModuleByType() {
    final DoubleType value = new DoubleType(123.456);

    final Module module = ops.module(InfinityOp.class, value);
    assertSame(value, module.getInput("arg"));

    assertFalse(Double.isInfinite(value.get()));
    module.run();
    assertTrue(Double.isInfinite(value.get()));
  }
Ejemplo n.º 5
0
  @Override
  public void compute(final IterableInterval<T> input, final DoubleType output) {
    final double[][] matrix = getCooccurrenceMatrix(input);

    final double[] pxplusy = coocPXPlusYFunc.compute(matrix);
    final int nrGrayLevels = matrix.length;
    final double average = sumAverageFunc.compute(input).getRealDouble();

    double res = 0;
    for (int i = 2; i <= 2 * nrGrayLevels; i++) {
      res += (i - average) * (i - average) * pxplusy[i];
    }

    output.set(res);
  }
Ejemplo n.º 6
0
  /** Tests {@link OpService#run(String, Object...)}. */
  @Test
  public void testAliases() {
    final DoubleType value = new DoubleType(123.456);

    assertFalse(Double.isInfinite(value.get()));
    final Object result = ops.run("infin", value);
    assertSame(value, result);
    assertTrue(Double.isInfinite(value.get()));

    value.set(0.0);
    assertFalse(Double.isInfinite(value.get()));
    final Object result2 = ops.run("inf", value);
    assertSame(value, result2);
    assertTrue(Double.isInfinite(value.get()));

    value.set(0.0);
    boolean noSuchAlias = false;
    try {
      ops.run("infini", value);
    } catch (final IllegalArgumentException exc) {
      noSuchAlias = true;
    }
    assertTrue(noSuchAlias);
  }
 private double measure(final Function<PointSet, DoubleType> func, final PointSet region) {
   final DoubleType output = new DoubleType();
   func.compute(region, output);
   return output.getRealDouble();
 }
Ejemplo n.º 8
0
 @Override
 public void compute(final DoubleType arg) {
   arg.set(Double.POSITIVE_INFINITY);
 }
Ejemplo n.º 9
0
 @Override
 public void compute(long[] input, DoubleType output) {
   output.setReal(input[position]);
 }