Skip to content

Commit 53cb07e

Browse files
committed
AbstractOpTest: standardize sample image helpers
* The static helper methods all include the name "Relative" to differentiate them from the non-static methods. * Added a non-static unsigned byte opener * Unsigned byte method naming is now consistent
1 parent 3d095b8 commit 53cb07e

8 files changed

Lines changed: 45 additions & 24 deletions

File tree

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/AbstractFeatureTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public Img<UnsignedByteType> getEllipsedBitImage(final long[] dim,
250250
}
251251

252252
protected static Img<FloatType> getTestImage2D() {
253-
return openFloatImg(AbstractFeatureTest.class, "features/2d_geometric_features_testlabel.tif");
253+
return openRelativeFloatImg(AbstractFeatureTest.class, "features/2d_geometric_features_testlabel.tif");
254254
}
255255

256256
protected static Polygon2D getPolygon() {
@@ -270,7 +270,7 @@ protected static Polygon2D getPolygon() {
270270
}
271271

272272
protected static Img<FloatType> getTestImage3D() {
273-
return openFloatImg(AbstractFeatureTest.class, "features/3d_geometric_features_testlabel.tif");
273+
return openRelativeFloatImg(AbstractFeatureTest.class, "features/3d_geometric_features_testlabel.tif");
274274
}
275275

276276
protected static Mesh getMesh() {

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/AbstractOpTest.java‎

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,35 +95,56 @@ private int pseudoRandom() {
9595
return seed = 3170425 * seed + 132102;
9696
}
9797

98-
99-
98+
/**
99+
* Open a sample image from a resource path relative to {@link AbstractOpTest}
100+
*/
100101
public Img<FloatType> openFloatImg(final String resourcePath) {
101-
return openFloatImg(getClass(), resourcePath);
102+
return openRelativeFloatImg(getClass(), resourcePath);
102103
}
103104

105+
/**
106+
* Open a sample image from a resource path relative to {@link AbstractOpTest}
107+
*/
104108
public Img<DoubleType> openDoubleImg(final String resourcePath) {
105-
return openDoubleImg(getClass(), resourcePath);
109+
return openRelativeDoubleImg(getClass(), resourcePath);
110+
}
111+
112+
/**
113+
* Open a sample image from a resource path relative to {@link AbstractOpTest}
114+
*/
115+
public Img<UnsignedByteType> openUnsignedByteImg(final String resourcePath)
116+
{
117+
return openRelativeUnsignedByteImg(getClass(), resourcePath);
106118
}
107119

108-
public static Img<FloatType> openFloatImg(final Class<?> c,
120+
/**
121+
* Open a sample image from a resource path relative to a specified base class
122+
*/
123+
public static Img<FloatType> openRelativeFloatImg(final Class<?> base,
109124
final String resourcePath)
110125
{
111-
final URL url = c.getResource(resourcePath);
126+
final URL url = base.getResource(resourcePath);
112127
return IO.openFloat(url.getPath()).getImg();
113128
}
114129

115-
public static Img<UnsignedByteType> openUnsignedByteType(final Class<?> c,
130+
/**
131+
* Open a sample image from a resource path relative to a specified base class
132+
*/
133+
public static Img<DoubleType> openRelativeDoubleImg(final Class<?> base,
116134
final String resourcePath)
117135
{
118-
final URL url = c.getResource(resourcePath);
119-
return IO.openUnsignedByte(url.getPath()).getImg();
136+
final URL url = base.getResource(resourcePath);
137+
return IO.openDouble(url.getPath()).getImg();
120138
}
121139

122-
public static Img<DoubleType> openDoubleImg(final Class<?> c,
140+
/**
141+
* Open a sample image from a resource path relative to a specified base class
142+
*/
143+
public static Img<UnsignedByteType> openRelativeUnsignedByteImg(final Class<?> base,
123144
final String resourcePath)
124145
{
125-
final URL url = c.getResource(resourcePath);
126-
return IO.openDouble(url.getPath()).getImg();
146+
final URL url = base.getResource(resourcePath);
147+
return IO.openUnsignedByte(url.getPath()).getImg();
127148
}
128149

129150
public static <T> RandomAccessible<T> deinterval(

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/features/haralick/HaralickFeatureTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class HaralickFeatureTest extends AbstractOpTest {
5959

6060
@BeforeEach
6161
public void loadImage() {
62-
img = openUnsignedByteType(AbstractOpTest.class, "features/haralick_test_img.tif");
62+
img = openRelativeUnsignedByteImg(AbstractOpTest.class, "features/haralick_test_img.tif");
6363
}
6464

6565
@Test

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/filter/tubeness/TubenessTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class TubenessTest extends AbstractOpTest {
4848

4949
@Test
5050
public void testTubeness() {
51-
Img<UnsignedByteType> input = openUnsignedByteType(DefaultTubeness.class, "TubesInput.png");
51+
Img<UnsignedByteType> input = openRelativeUnsignedByteImg(DefaultTubeness.class, "TubesInput.png");
5252
Img<DoubleType> expected = openDoubleImg("tube.tif");
5353

5454
final double scale = 5;

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/image/watershed/WatershedBinarySingleSigmaTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class WatershedBinarySingleSigmaTest extends AbstractOpTest {
5959
@Test
6060
public void test() {
6161
// load test image
62-
Img<FloatType> watershedTestImg = openFloatImg(WatershedTest.class, "watershed_test_image.png");
62+
Img<FloatType> watershedTestImg = openRelativeFloatImg(WatershedTest.class, "watershed_test_image.png");
6363

6464
// retrieve an ExecutorService TODO is there a better way to do this?
6565
ExecutorService es = threads.getExecutorService();

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/image/watershed/WatershedBinaryTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class WatershedBinaryTest extends AbstractOpTest {
5858
@Test
5959
public void test() {
6060
// load test image
61-
Img<FloatType> watershedTestImg = openFloatImg(WatershedTest.class, "watershed_test_image.png");
61+
Img<FloatType> watershedTestImg = openRelativeFloatImg(WatershedTest.class, "watershed_test_image.png");
6262

6363
// retrieve an ExecutorService TODO is there a better way to do this?
6464
ExecutorService es = threads.getExecutorService();

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/image/watershed/WatershedTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class WatershedTest extends AbstractOpTest {
6363
@Test
6464
public void test() {
6565
// load test image
66-
Img<FloatType> watershedTestImg = openFloatImg(WatershedTest.class, "watershed_test_image.png");
66+
Img<FloatType> watershedTestImg = openRelativeFloatImg(WatershedTest.class, "watershed_test_image.png");
6767

6868
// retrieve an ExecutorService TODO is there a better way to do this?
6969
ExecutorService es = threads.getExecutorService();

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/morphology/thin/ThinningTest.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class ThinningTest extends AbstractOpTest {
5151

5252
@BeforeEach
5353
public void initialize() {
54-
Img<FloatType> testImg = openFloatImg(AbstractOpTest.class, "features/3d_geometric_features_testlabel.tif");
54+
Img<FloatType> testImg = openRelativeFloatImg(AbstractOpTest.class, "features/3d_geometric_features_testlabel.tif");
5555
in = ops.op("create.img").input(testImg, new BitType()).outType(new Nil<Img<BitType>>() {}).apply();
5656
target = ops.op("create.img").input(in, new BitType()).outType(new Nil<Img<BitType>>() {}).apply();
5757
ops.op("convert.bit").input(testImg).output(in).compute();
@@ -61,29 +61,29 @@ public void initialize() {
6161
@Test
6262
public void testThinGuoHall() {
6363
final Img<BitType> out = ops.op("morphology.thinGuoHall").input(in).outType(new Nil<Img<BitType>>() {}).apply();
64-
ops.op("convert.bit").input(openFloatImg(AbstractThin.class, "result_guoHall.tif")).output(target).compute();
64+
ops.op("convert.bit").input(openRelativeFloatImg(AbstractThin.class, "result_guoHall.tif")).output(target).compute();
6565
ImgLib2Assert.assertImageEquals(target, out);
6666
}
6767

6868
@Test
6969
public void testThinHilditch() {
7070
final Img<BitType> out = ops.op("morphology.thinHilditch").input(in).outType(new Nil<Img<BitType>>() {}).apply();
71-
ops.op("convert.bit").input(openFloatImg(AbstractThin.class, "result_hilditch.tif")).output(target).compute();
71+
ops.op("convert.bit").input(openRelativeFloatImg(AbstractThin.class, "result_hilditch.tif")).output(target).compute();
7272
ImgLib2Assert.assertImageEquals(target, out);
7373
}
7474

7575
@Test
7676
public void testMorphological() {
7777
final Img<BitType> out = ops.op("morphology.thinMorphological").input(in).outType(new Nil<Img<BitType>>() {})
7878
.apply();
79-
ops.op("convert.bit").input(openFloatImg(AbstractThin.class, "result_morphological.tif")).output(target).compute();
79+
ops.op("convert.bit").input(openRelativeFloatImg(AbstractThin.class, "result_morphological.tif")).output(target).compute();
8080
ImgLib2Assert.assertImageEquals(target, out);
8181
}
8282

8383
@Test
8484
public void testZhangSuen() {
8585
final Img<BitType> out = ops.op("morphology.thinZhangSuen").input(in).outType(new Nil<Img<BitType>>() {}).apply();
86-
ops.op("convert.bit").input(openFloatImg(AbstractThin.class, "result_zhangSuen.tif")).output(target).compute();
86+
ops.op("convert.bit").input(openRelativeFloatImg(AbstractThin.class, "result_zhangSuen.tif")).output(target).compute();
8787
ImgLib2Assert.assertImageEquals(target, out);
8888
}
8989
}

0 commit comments

Comments
 (0)