Skip to content

Commit 03e0bc5

Browse files
gselzerwiedenm
authored andcommitted
Migrate transform ops
1 parent 864d812 commit 03e0bc5

31 files changed

Lines changed: 3730 additions & 2 deletions

File tree

src/main/java/net/imagej/ops/transform/Transforms.java

Lines changed: 420 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/org/scijava/ops/util/Functions.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
import com.google.common.collect.ImmutableBiMap;
55

66
import java.lang.reflect.Type;
7-
import java.util.Collections;
87
import java.util.HashMap;
98
import java.util.Map;
109
import java.util.function.BiFunction;
1110
import java.util.function.Function;
1211
import java.util.function.Supplier;
1312

1413
import org.scijava.ops.OpService;
15-
import org.scijava.ops.core.Op;
1614
import org.scijava.ops.core.function.Function3;
1715
import org.scijava.ops.core.function.Function4;
1816
import org.scijava.ops.core.function.Function5;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package net.imagej.ops.transform.addDimensionView;
30+
31+
import static org.junit.Assert.assertEquals;
32+
33+
import java.util.function.Function;
34+
35+
import net.imglib2.RandomAccessible;
36+
import net.imglib2.RandomAccessibleInterval;
37+
import net.imglib2.img.Img;
38+
import net.imglib2.img.array.ArrayImgFactory;
39+
import net.imglib2.type.numeric.real.DoubleType;
40+
import net.imglib2.view.IntervalView;
41+
import net.imglib2.view.MixedTransformView;
42+
import net.imglib2.view.Views;
43+
44+
import org.junit.Test;
45+
import org.scijava.ops.AbstractTestEnvironment;
46+
import org.scijava.ops.core.function.Function3;
47+
import org.scijava.ops.types.Nil;
48+
49+
/**
50+
* Tests {@link net.imagej.ops.Ops.Transform.AddDimensionView} ops.
51+
* <p>
52+
* This test only checks if the op call works with all parameters and that the
53+
* result is equal to that of the {@link Views} method call. It is not a
54+
* correctness test of {@link Views} itself.
55+
* </p>
56+
*
57+
* @author Tim-Oliver Buchholz (University of Konstanz)
58+
*/
59+
public class AddDimensionViewTest extends AbstractTestEnvironment {
60+
61+
@Test
62+
public void addDimensionTest() {
63+
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
64+
65+
MixedTransformView<DoubleType> il2 = Views.addDimension((RandomAccessible<DoubleType>) img);
66+
67+
Function<RandomAccessible<DoubleType>, MixedTransformView<DoubleType>> addDimFunc = ops.findOp(
68+
"transform.addDimensionView",
69+
new Nil<Function<RandomAccessible<DoubleType>, MixedTransformView<DoubleType>>>() {
70+
}, new Nil[] { new Nil<RandomAccessible<DoubleType>>() {
71+
} }, new Nil<MixedTransformView<DoubleType>>() {
72+
});
73+
MixedTransformView<DoubleType> opr = addDimFunc.apply(img);
74+
75+
assertEquals(il2.numDimensions(), opr.numDimensions());
76+
boolean[] il2Transform = new boolean[3];
77+
boolean[] oprTransform = new boolean[3];
78+
il2.getTransformToSource().getComponentZero(il2Transform);
79+
opr.getTransformToSource().getComponentZero(oprTransform);
80+
for (int i = 0; i < il2Transform.length; i++) {
81+
assertEquals(il2Transform[i], oprTransform[i]);
82+
}
83+
}
84+
85+
@Test
86+
public void addDimensionMinMaxTest() {
87+
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
88+
long max = 20;
89+
long min = 0;
90+
91+
IntervalView<DoubleType> il2 = Views.addDimension(img, min, max);
92+
93+
Function3<RandomAccessibleInterval<DoubleType>, Long, Long, IntervalView<DoubleType>> addDimFunc = ops
94+
.findOp(
95+
"transform.addDimensionView",
96+
new Nil<Function3<RandomAccessibleInterval<DoubleType>, Long, Long, IntervalView<DoubleType>>>() {
97+
}, new Nil[] { new Nil<RandomAccessibleInterval<DoubleType>>() {
98+
}, new Nil<Long>() {
99+
}, new Nil<Long>() {
100+
} }, new Nil<IntervalView<DoubleType>>() {
101+
});
102+
IntervalView<DoubleType> opr = addDimFunc.apply(img, min, max);
103+
104+
assertEquals(il2.numDimensions(), opr.numDimensions(), 0.0);
105+
for (int i = 0; i < il2.numDimensions(); i++) {
106+
assertEquals(il2.dimension(i), opr.dimension(i), 0.0);
107+
}
108+
}
109+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package net.imagej.ops.transform.collapseNumericView;
30+
31+
import static org.junit.Assert.assertEquals;
32+
33+
import java.util.function.BiFunction;
34+
import java.util.function.Function;
35+
36+
import net.imglib2.RandomAccessible;
37+
import net.imglib2.RandomAccessibleInterval;
38+
import net.imglib2.img.Img;
39+
import net.imglib2.img.array.ArrayImgFactory;
40+
import net.imglib2.type.numeric.NativeARGBDoubleType;
41+
import net.imglib2.view.Views;
42+
import net.imglib2.view.composite.CompositeIntervalView;
43+
import net.imglib2.view.composite.CompositeView;
44+
import net.imglib2.view.composite.NumericComposite;
45+
46+
import org.junit.Test;
47+
import org.scijava.ops.AbstractTestEnvironment;
48+
import org.scijava.ops.types.Nil;
49+
import org.scijava.ops.util.Functions;
50+
51+
/**
52+
* Tests {@link net.imagej.ops.Ops.Transform.CollapseNumericView} ops.
53+
* <p>
54+
* This test only checks if the op call works with all parameters and that the
55+
* result is equal to that of the {@link Views} method call. It is not a
56+
* correctness test of {@link Views} itself.
57+
* </p>
58+
*
59+
* @author Tim-Oliver Buchholz (University of Konstanz)
60+
*/
61+
public class CollapseNumericViewTest extends AbstractTestEnvironment {
62+
63+
@Test
64+
public void defaultCollapseNumericTest() {
65+
66+
Function<RandomAccessibleInterval<NativeARGBDoubleType>, CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>>> collapseFunc = Functions
67+
.unary(ops, "transform.collapseNumericView",
68+
new Nil<RandomAccessibleInterval<NativeARGBDoubleType>>() {
69+
},
70+
new Nil<CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>>>() {
71+
});
72+
73+
Img<NativeARGBDoubleType> img = new ArrayImgFactory<NativeARGBDoubleType>().create(new int[] { 10, 10 },
74+
new NativeARGBDoubleType());
75+
76+
CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> il2 = Views
77+
.collapseNumeric((RandomAccessibleInterval<NativeARGBDoubleType>) img);
78+
CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> opr = collapseFunc
79+
.apply(img);
80+
81+
assertEquals(il2.numDimensions(), opr.numDimensions());
82+
83+
BiFunction<RandomAccessible<NativeARGBDoubleType>, Integer, CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>>> collapseFuncRA = Functions
84+
.binary(ops, "transform.collapseNumericView",
85+
new Nil<RandomAccessible<NativeARGBDoubleType>>() {
86+
}, new Nil<Integer>() {
87+
},
88+
new Nil<CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>>>() {
89+
});
90+
91+
CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> il2_2 = Views
92+
.collapseNumeric((RandomAccessible<NativeARGBDoubleType>) img, 1);
93+
CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> opr_2 = collapseFuncRA.apply(img,
94+
1);
95+
96+
assertEquals(il2_2.numDimensions(), opr_2.numDimensions());
97+
}
98+
99+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package net.imagej.ops.transform.collapseRealView;
30+
31+
import static org.junit.Assert.assertEquals;
32+
33+
import java.util.function.BiFunction;
34+
import java.util.function.Function;
35+
36+
import net.imglib2.RandomAccessible;
37+
import net.imglib2.RandomAccessibleInterval;
38+
import net.imglib2.img.Img;
39+
import net.imglib2.img.array.ArrayImgFactory;
40+
import net.imglib2.type.numeric.real.DoubleType;
41+
import net.imglib2.view.Views;
42+
import net.imglib2.view.composite.CompositeIntervalView;
43+
import net.imglib2.view.composite.CompositeView;
44+
import net.imglib2.view.composite.RealComposite;
45+
46+
import org.junit.Test;
47+
import org.scijava.ops.AbstractTestEnvironment;
48+
import org.scijava.ops.types.Nil;
49+
import org.scijava.ops.util.Functions;
50+
51+
/**
52+
* Tests {@link net.imagej.ops.Ops.Transform.CollapseRealView} ops.
53+
* <p>
54+
* This test only checks if the op call works with all parameters and that the
55+
* result is equal to that of the {@link Views} method call. It is not a
56+
* correctness test of {@link Views} itself.
57+
* </p>
58+
*
59+
* @author Tim-Oliver Buchholz (University of Konstanz)
60+
*/
61+
public class CollapseRealViewTest extends AbstractTestEnvironment {
62+
63+
@Test
64+
public void defaultCollapseRealTest() {
65+
66+
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 },
67+
new DoubleType());
68+
69+
Function<RandomAccessibleInterval<DoubleType>, CompositeIntervalView<DoubleType, RealComposite<DoubleType>>> collapseFunc = Functions
70+
.unary(ops, "transform.collapseRealView", new Nil<RandomAccessibleInterval<DoubleType>>() {
71+
}, new Nil<CompositeIntervalView<DoubleType, RealComposite<DoubleType>>>() {
72+
});
73+
74+
CompositeIntervalView<DoubleType, RealComposite<DoubleType>> il2 = Views
75+
.collapseReal((RandomAccessibleInterval<DoubleType>) img);
76+
CompositeIntervalView<DoubleType, RealComposite<DoubleType>> opr = collapseFunc.apply(img);
77+
78+
assertEquals(il2.numDimensions(), opr.numDimensions());
79+
80+
BiFunction<RandomAccessible<DoubleType>, Integer, CompositeView<DoubleType, RealComposite<DoubleType>>> collapseFuncRA = Functions
81+
.binary(ops, "transform.collapseRealView", new Nil<RandomAccessible<DoubleType>>() {
82+
}, new Nil<Integer>() {
83+
}, new Nil<CompositeView<DoubleType, RealComposite<DoubleType>>>() {
84+
});
85+
86+
CompositeView<DoubleType, RealComposite<DoubleType>> il2_2 = Views
87+
.collapseReal((RandomAccessible<DoubleType>) img, 1);
88+
CompositeView<DoubleType, RealComposite<DoubleType>> opr_2 = collapseFuncRA.apply(img, 1);
89+
90+
assertEquals(il2_2.numDimensions(), opr_2.numDimensions());
91+
}
92+
93+
}

0 commit comments

Comments
 (0)