Skip to content

Commit 11923cc

Browse files
committed
Move test to its own file
1 parent 3f5dd0e commit 11923cc

2 files changed

Lines changed: 75 additions & 35 deletions

File tree

scijava-ops-image/src/test/java/org/scijava/ops/image/filter/convolve/ConvolveTest.java

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,14 @@
3030

3131
package org.scijava.ops.image.filter.convolve;
3232

33-
import net.imglib2.*;
34-
import net.imglib2.img.array.ArrayImgs;
35-
import net.imglib2.type.numeric.integer.UnsignedByteType;
36-
import net.imglib2.view.Views;
37-
import org.apache.commons.math3.complex.Complex;
38-
import org.junit.jupiter.api.Assertions;
3933
import org.scijava.ops.image.AbstractOpTest;
34+
import net.imglib2.RandomAccessibleInterval;
4035
import net.imglib2.outofbounds.OutOfBoundsFactory;
4136
import net.imglib2.type.numeric.complex.ComplexFloatType;
4237
import net.imglib2.type.numeric.real.FloatType;
4338
import org.junit.jupiter.api.Test;
4439
import org.scijava.types.Nil;
4540

46-
import java.util.Arrays;
47-
4841
/**
4942
* Tests involving convolvers.
5043
*/
@@ -66,33 +59,6 @@ public void testConvolve() {
6659
{} //
6760
).outType(new Nil<RandomAccessibleInterval<FloatType>>() {}).function();
6861
}
69-
70-
@Test
71-
public void testCorrelate() {
72-
// Create an image with the center pixel set
73-
var img = ArrayImgs.unsignedBytes(9, 9);
74-
var impulse = new long[] {4, 4};
75-
img.randomAccess().setPositionAndGet(impulse).set(1);
76-
77-
// Create an identity kernel
78-
var kernel = ArrayImgs.unsignedBytes(5, 5);
79-
kernel.getAt(2, 2).set(1);
80-
81-
// Correlate with Ops
82-
var output = ops.op("filter.correlate").input(img, kernel, new FloatType(), new ComplexFloatType()).apply();
83-
Assertions.assertInstanceOf(RandomAccessibleInterval.class, output);
84-
var actual = (RandomAccessibleInterval<FloatType>) output;
85-
86-
// Check the result
87-
var cursor = actual.cursor();
88-
while (cursor.hasNext()) {
89-
var actualValue = cursor.next().get();
90-
var pos = cursor.positionAsLongArray();
91-
// The only pixel that should be set is the center pixel.
92-
var expected = Arrays.equals(impulse, pos) ? 1 : 0;
93-
Assertions.assertEquals(expected, actualValue, 1e-6);
94-
}
95-
}
9662
}
9763
//
9864
// /** Tests that the correct convolver is selected when using a small kernel. */
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* #%L
3+
* Image processing operations for SciJava Ops.
4+
* %%
5+
* Copyright (C) 2014 - 2025 SciJava 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+
//
30+
31+
package org.scijava.ops.image.filter.correlate;
32+
33+
import net.imglib2.RandomAccessibleInterval;
34+
import net.imglib2.img.array.ArrayImgs;
35+
import net.imglib2.type.numeric.complex.ComplexFloatType;
36+
import net.imglib2.type.numeric.real.FloatType;
37+
import org.junit.jupiter.api.Assertions;
38+
import org.junit.jupiter.api.Test;
39+
import org.scijava.ops.image.AbstractOpTest;
40+
41+
import java.util.Arrays;
42+
43+
/**
44+
* Tests involving convolvers.
45+
*/
46+
public class CorrelateTest extends AbstractOpTest {
47+
48+
@Test
49+
public void testCorrelate() {
50+
// Create an image with the center pixel set
51+
var img = ArrayImgs.unsignedBytes(9, 9);
52+
var impulse = new long[] {4, 4};
53+
img.randomAccess().setPositionAndGet(impulse).set(1);
54+
55+
// Create an identity kernel
56+
var kernel = ArrayImgs.unsignedBytes(5, 5);
57+
kernel.getAt(2, 2).set(1);
58+
59+
// Correlate with Ops
60+
var output = ops.op("filter.correlate").input(img, kernel, new FloatType(), new ComplexFloatType()).apply();
61+
Assertions.assertInstanceOf(RandomAccessibleInterval.class, output);
62+
var actual = (RandomAccessibleInterval<FloatType>) output;
63+
64+
// Check the result
65+
var cursor = actual.cursor();
66+
while (cursor.hasNext()) {
67+
var actualValue = cursor.next().get();
68+
var pos = cursor.positionAsLongArray();
69+
// The only pixel that should be set is the center pixel.
70+
var expected = Arrays.equals(impulse, pos) ? 1 : 0;
71+
Assertions.assertEquals(expected, actualValue, 1e-6);
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)