|
31 | 31 |
|
32 | 32 | import static org.junit.jupiter.api.Assertions.assertEquals; |
33 | 33 |
|
| 34 | +import net.imglib2.FinalInterval; |
| 35 | +import net.imglib2.RandomAccessibleInterval; |
| 36 | +import net.imglib2.img.array.ArrayImgs; |
| 37 | +import net.imglib2.view.Views; |
34 | 38 | import org.scijava.ops.image.AbstractOpTest; |
35 | 39 | import org.scijava.ops.image.util.TestImgGeneration; |
36 | 40 | import net.imglib2.RandomAccess; |
@@ -82,6 +86,37 @@ public void testProjector() { |
82 | 86 | testEquality(out1, out2); |
83 | 87 | } |
84 | 88 |
|
| 89 | + /** |
| 90 | + * Ensures {@code "transform.project"} runs only within the passed interval. |
| 91 | + */ |
| 92 | + @Test |
| 93 | + public void testInterval() { |
| 94 | + // Set up img[x, y, z] = z |
| 95 | + var input = ArrayImgs.unsignedBytes(10, 10, 10); |
| 96 | + for(int x = 0; x < 10; x++) { |
| 97 | + for(int y = 0; y < 10; y++) { |
| 98 | + for(int z = 0; z < 10; z++) { |
| 99 | + input.getAt(x, y, z).set(z); |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + // Create an interval containing 2<=z<=4 |
| 104 | + var intervaled = Views.interval(input, new FinalInterval(new long[] {0, 0, 2}, new long[] {10, 10, 4})); |
| 105 | + |
| 106 | + // Project on the interval |
| 107 | + var out = ArrayImgs.unsignedBytes(10, 10); |
| 108 | + var op = ops.op("stats.sum").input(intervaled).outType(UnsignedByteType.class).computer(); |
| 109 | + ops.op("transform.project").input(intervaled, op, PROJECTION_DIM).output(out).compute(); |
| 110 | + |
| 111 | + // Assert that the projection (summation) only covered z=2, z=3, z=4 |
| 112 | + var outCursor = out.cursor(); |
| 113 | + while (outCursor.hasNext()) { |
| 114 | + // 2 + 3 + 4 = 9 |
| 115 | + assertEquals(9, outCursor.next().get()); |
| 116 | + } |
| 117 | + |
| 118 | + } |
| 119 | + |
85 | 120 | private void testEquality(final Img<UnsignedByteType> img1, |
86 | 121 | final Img<UnsignedByteType> img2) |
87 | 122 | { |
|
0 commit comments