Skip to content

Commit 6ee3416

Browse files
committed
Ensure projection within provided interval
Before the changes to the Op, this test failed, because the projection operated on the interval [0, max-min] for an image defined on interval [min, max]. With the changes to the Op, this Op works on [min, max]
1 parent 336acdb commit 6ee3416

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

  • scijava-ops-image/src/test/java/org/scijava/ops/image/transform/project

scijava-ops-image/src/test/java/org/scijava/ops/image/transform/project/ProjectTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
import static org.junit.jupiter.api.Assertions.assertEquals;
3333

34+
import net.imglib2.FinalInterval;
35+
import net.imglib2.RandomAccessibleInterval;
36+
import net.imglib2.img.array.ArrayImgs;
37+
import net.imglib2.view.Views;
3438
import org.scijava.ops.image.AbstractOpTest;
3539
import org.scijava.ops.image.util.TestImgGeneration;
3640
import net.imglib2.RandomAccess;
@@ -82,6 +86,37 @@ public void testProjector() {
8286
testEquality(out1, out2);
8387
}
8488

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+
85120
private void testEquality(final Img<UnsignedByteType> img1,
86121
final Img<UnsignedByteType> img2)
87122
{

0 commit comments

Comments
 (0)