Skip to content

Commit c9d46d6

Browse files
committed
FrangiVesselnessTest: purge ScriptService usage
In some Java environments, JavaScript is not available or not reliable. Java 6's Rhino became Java 8's Nashorn and was then removed in Java 14. Let's just compute this input image the old-fashioned way: in Java. ;-)
1 parent 0b1a42c commit c9d46d6

1 file changed

Lines changed: 22 additions & 26 deletions

File tree

imagej/imagej-ops2/src/test/java/net/imagej/ops2/filter/vesselness/FrangiVesselnessTest.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@
4848
import org.junit.jupiter.api.Test;
4949
import org.scijava.Context;
5050
import org.scijava.cache.CacheService;
51-
import org.scijava.ops.api.OpBuilder;
5251
import org.scijava.ops.engine.OpService;
5352
import org.scijava.plugin.PluginService;
54-
import org.scijava.script.ScriptService;
5553
import org.scijava.thread.ThreadService;
5654

5755
/**
@@ -65,9 +63,8 @@ public class FrangiVesselnessTest{
6563
protected static OpService ops;
6664

6765
@BeforeAll public static void setUp() {
68-
context =
69-
new Context(OpService.class, CacheService.class, ThreadService.class,
70-
ScriptService.class, PluginService.class);
66+
context = new Context(OpService.class, CacheService.class,
67+
ThreadService.class, PluginService.class);
7168
ops = context.service(OpService.class);
7269
}
7370

@@ -78,46 +75,45 @@ public static void tearDown() {
7875
ops = null;
7976
}
8077

81-
private static OpBuilder op(String name) {
82-
return ops.op(name);
83-
}
84-
85-
private Img<FloatType> openFloatImg(
86-
final String resourcePath)
87-
{
78+
private Img<FloatType> openFloatImg(final String resourcePath) {
8879
final URL url = getClass().getResource(resourcePath);
8980
return IO.openFloat(url.getPath()).getImg();
9081
}
9182

9283
@Test
9384
public void regressionTest() throws Exception {
85+
// compute input image
86+
final int w = 256, h = 256;
87+
final double[] inputValues = new double[256 * 256];
88+
for (int y = 0; y < h; y++) {
89+
for (int x = 0; x < w; x++) {
90+
inputValues[w * y + x] = Math.tan(0.3 * x) + Math.tan(0.1 * y);
91+
}
92+
}
93+
final Img<DoubleType> inputImg = ArrayImgs.doubles(inputValues, w, h);
9494

95-
// load in input image and expected output image.
96-
Img<DoubleType> inputImg = ArrayImgs.doubles(256, 256);
97-
ops.op("image.equation")
98-
.input("Math.tan(0.3*p[0]) + Math.tan(0.1*p[1])", context.getService(ScriptService.class))
99-
.output(inputImg).compute();
100-
Img<FloatType> expectedOutput = ((Img<FloatType>) openFloatImg("Result.tif"));
95+
// load expected output image
96+
final Img<FloatType> expectedOutput = openFloatImg("Result.tif");
10197

102-
// create ouput image
103-
long[] dims = new long[inputImg.numDimensions()];
98+
// create output image
99+
final long[] dims = new long[inputImg.numDimensions()];
104100
inputImg.dimensions(dims);
105-
Img<FloatType> actualOutput = ArrayImgs.floats(dims);
101+
final Img<FloatType> actualOutput = ArrayImgs.floats(dims);
106102

107103
// scale over which the filter operates (sensitivity)
108-
int scale = 1;
104+
final int scale = 1;
109105

110106
// physical spacing between data points (1,1 since I got it from the
111107
// computer)
112-
double[] spacing = { 1, 1 };
108+
final double[] spacing = { 1, 1 };
113109

114110
// run the op
115111
ops.op("filter.frangiVesselness").input(inputImg, spacing, scale).output(actualOutput).compute();
116112

117113
// compare the output image data to that stored in the file.
118-
Cursor<FloatType> cursor = Views.iterable(actualOutput).localizingCursor();
119-
RandomAccess<FloatType> actualRA = actualOutput.randomAccess();
120-
RandomAccess<FloatType> expectedRA = expectedOutput.randomAccess();
114+
final Cursor<FloatType> cursor = Views.iterable(actualOutput).localizingCursor();
115+
final RandomAccess<FloatType> actualRA = actualOutput.randomAccess();
116+
final RandomAccess<FloatType> expectedRA = expectedOutput.randomAccess();
121117

122118
while (cursor.hasNext()) {
123119
cursor.fwd();

0 commit comments

Comments
 (0)