Skip to content

Commit f31805f

Browse files
committed
Create ImgLib2 Descriptors for common types
1 parent e7f7dda commit f31805f

3 files changed

Lines changed: 160 additions & 1 deletion

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
package org.scijava.ops.image.describe;
3+
4+
import net.imglib2.IterableInterval;
5+
import net.imglib2.RandomAccessibleInterval;
6+
import net.imglib2.roi.labeling.ImgLabeling;
7+
import net.imglib2.type.numeric.ComplexType;
8+
import net.imglib2.type.numeric.IntegerType;
9+
import net.imglib2.type.numeric.NumericType;
10+
import net.imglib2.type.numeric.RealType;
11+
import org.scijava.types.Nil;
12+
13+
import java.util.function.Function;
14+
15+
public class ImgLib2Descriptors< //
16+
A, //
17+
C extends ComplexType<C>, //
18+
I extends IntegerType<I>, //
19+
T extends RealType<T> //
20+
> {
21+
22+
/**
23+
* @input the type to describe
24+
* @output the description
25+
* @implNote op name="engine.describe"
26+
*/
27+
public final Function<Nil<IterableInterval<A>>, String> iiDesc = //
28+
in -> "image";
29+
30+
/**
31+
* @input the type to describe
32+
* @output the description
33+
* @implNote op name="engine.describe", priority="100."
34+
*/
35+
public final Function<Nil<RandomAccessibleInterval<A>>, String> raiDesc = //
36+
in -> "image";
37+
38+
/**
39+
* @input the type to describe
40+
* @output the description
41+
* @implNote op name="engine.describe", priority="1000."
42+
*/
43+
public final Function<Nil<ImgLabeling<A, I>>, String> imgLabelDesc = //
44+
in -> "labels";
45+
46+
/**
47+
* @input the type to describe
48+
* @output the description
49+
* @implNote op name="engine.describe", priority='100.'
50+
*/
51+
public final Function<Nil<T>, String> realTypeDesc = //
52+
in -> "number";
53+
54+
/**
55+
* @input the type to describe
56+
* @output the description
57+
* @implNote op name="engine.describe"
58+
*/
59+
public final Function<Nil<C>, String> complexTypeDesc = //
60+
in -> "complex number";
61+
}

scijava-ops-image/src/test/java/org/scijava/ops/image/OpRegressionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class OpRegressionTest {
4242

4343
@Test
4444
public void opDiscoveryRegressionIT() {
45-
long expected = 1912;
45+
long expected = 1922;
4646
long actual = ops.infos().size();
4747
assertEquals(expected, actual);
4848
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2+
package org.scijava.ops.image.describe;
3+
4+
import net.imglib2.IterableInterval;
5+
import net.imglib2.RandomAccessibleInterval;
6+
import net.imglib2.loops.LoopBuilder;
7+
import net.imglib2.roi.labeling.ImgLabeling;
8+
import net.imglib2.type.numeric.ComplexType;
9+
import net.imglib2.type.numeric.IntegerType;
10+
import net.imglib2.type.numeric.RealType;
11+
import org.junit.jupiter.api.Assertions;
12+
import org.junit.jupiter.api.Test;
13+
import org.scijava.ops.image.AbstractOpTest;
14+
15+
public class DescriptorsTest extends AbstractOpTest {
16+
17+
/**
18+
* @implNote op name=example.describeRealType, type=Inplace
19+
*/
20+
public static <T extends RealType<T>> void realType(T in) {
21+
in.mul(in);
22+
}
23+
24+
@Test
25+
public void testRealTypeDescription() {
26+
var expected = "example.describeRealType:\n" +
27+
"\t- (@MUTABLE number) -> None";
28+
var actual = ops.help("example.describeRealType");
29+
Assertions.assertEquals(expected, actual);
30+
}
31+
32+
/**
33+
* @implNote op name=example.describeComplexType, type=Inplace
34+
*/
35+
public static <T extends ComplexType<T>> void complexType(T in) {
36+
in.mul(in);
37+
}
38+
39+
@Test
40+
public void testComplexTypeDescription() {
41+
var expected = "example.describeComplexType:\n" +
42+
"\t- (@MUTABLE complex number) -> None";
43+
var actual = ops.help("example.describeComplexType");
44+
Assertions.assertEquals(expected, actual);
45+
}
46+
47+
/**
48+
* @implNote op name=example.describeRAI, type=Inplace
49+
*/
50+
public static <T extends RealType<T>> void randomAccessibleInterval(
51+
RandomAccessibleInterval<T> in)
52+
{
53+
LoopBuilder.setImages(in).forEachPixel(i -> i.mul(i));
54+
}
55+
56+
@Test
57+
public void testRAIDescription() {
58+
var expected = "example.describeRAI:\n" + "\t- (@MUTABLE image) -> None";
59+
var actual = ops.help("example.describeRAI");
60+
Assertions.assertEquals(expected, actual);
61+
}
62+
63+
/**
64+
* @implNote op name=example.describeII, type=Inplace
65+
*/
66+
public static <T extends RealType<T>> void iterableInterval(
67+
IterableInterval<T> in)
68+
{
69+
var c = in.cursor();
70+
while (c.hasNext()) {
71+
var i = c.next();
72+
i.mul(i);
73+
}
74+
}
75+
76+
@Test
77+
public void testIIDescription() {
78+
var expected = "example.describeII:\n" + "\t- (@MUTABLE image) -> None";
79+
var actual = ops.help("example.describeII");
80+
Assertions.assertEquals(expected, actual);
81+
}
82+
83+
/**
84+
* @implNote op name=example.describeImgLabeling, type=Inplace
85+
*/
86+
public static <T, I extends IntegerType<I>> void imgLabeling(
87+
ImgLabeling<T, I> in)
88+
{}
89+
90+
@Test
91+
public void testImgLabelingDescription() {
92+
var expected = "example.describeImgLabeling:\n" +
93+
"\t- (@MUTABLE labels) -> None";
94+
var actual = ops.help("example.describeImgLabeling");
95+
Assertions.assertEquals(expected, actual);
96+
}
97+
98+
}

0 commit comments

Comments
 (0)