Skip to content

Commit 341a022

Browse files
committed
update unit tests for computation of 3D distance maps on label images
1 parent 9985665 commit 341a022

3 files changed

Lines changed: 170 additions & 19 deletions

File tree

‎src/test/java/inra/ijpb/label/distmap/ChamferDistanceTransform3DFloatTest.java‎

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,74 @@ public void test_distanceMap_Borgefors()
7070
* Test method for {@link inra.ijpb.label.distmap.ChamferDistanceTransform3DFloat#distanceMap(ij.ImageStack)}.
7171
*/
7272
@Test
73-
public void test_distanceMap_Svensson()
73+
public void test_distanceMap_Svensson_sameAsBorgefors()
7474
{
7575
// create 3D image containing a cube
76-
ImageStack image = ImageStack.create(20, 20, 20, 8);
77-
for (int z = 2; z < 19; z++)
76+
ImageStack image = TestImages.createStack_eightCuboids();
77+
78+
ChamferMask3D mask0 = ChamferMask3D.BORGEFORS;
79+
DistanceTransform3D refAlgo = new ChamferDistanceTransform3DFloat(mask0, true);
80+
ImageStack ref = refAlgo.distanceMap(image);
81+
82+
ChamferMask3D mask = ChamferMask3D.SVENSSON_3_4_5_7;
83+
DistanceTransform3D algo = new ChamferDistanceTransform3DFloat(mask, true);
84+
85+
ImageStack result = algo.distanceMap(image);
86+
87+
assertEquals(32, result.getBitDepth());
88+
assertEquals(image.getWidth(), result.getWidth());
89+
assertEquals(image.getHeight(), result.getHeight());
90+
assertEquals(image.getSize(), result.getSize());
91+
92+
for (int z = 0; z < result.getSize(); z++)
7893
{
79-
for (int y = 2; y < 19; y++)
94+
for (int y = 0; y < result.getHeight(); y++)
8095
{
81-
for (int x = 2; x < 19; x++)
96+
for (int x = 0; x < result.getWidth(); x++)
8297
{
83-
image.setVoxel(x, y, z, 255);
98+
double refValue = ref.getVoxel(x, y, z);
99+
double value = result.getVoxel(x, y, z);
100+
assertEquals(refValue, value, 0.01);
84101
}
85102
}
86103
}
104+
}
105+
106+
/**
107+
* Test method for {@link inra.ijpb.label.distmap.ChamferDistanceTransform3DFloat#distanceMap(ij.ImageStack)}.
108+
*/
109+
@Test
110+
public void test_distanceMap_Svensson_adjacentCubes_sameAsBorgefors()
111+
{
112+
// create 3D image containing a cube
113+
ImageStack image = TestImages.createStack_eightAdjacentCubes();
114+
115+
ChamferMask3D mask0 = ChamferMask3D.BORGEFORS;
116+
DistanceTransform3D refAlgo = new ChamferDistanceTransform3DFloat(mask0, true);
117+
ImageStack ref = refAlgo.distanceMap(image);
87118

88119
ChamferMask3D mask = ChamferMask3D.SVENSSON_3_4_5_7;
89120
DistanceTransform3D algo = new ChamferDistanceTransform3DFloat(mask, true);
121+
90122
ImageStack result = algo.distanceMap(image);
91-
123+
92124
assertEquals(32, result.getBitDepth());
93-
double middle = result.getVoxel(10, 10, 10);
94-
assertEquals(9, middle, 0.1);
125+
assertEquals(image.getWidth(), result.getWidth());
126+
assertEquals(image.getHeight(), result.getHeight());
127+
assertEquals(image.getSize(), result.getSize());
128+
129+
for (int z = 0; z < result.getSize(); z++)
130+
{
131+
for (int y = 0; y < result.getHeight(); y++)
132+
{
133+
for (int x = 0; x < result.getWidth(); x++)
134+
{
135+
double refValue = ref.getVoxel(x, y, z);
136+
double value = result.getVoxel(x, y, z);
137+
assertEquals(refValue, value, 0.01);
138+
}
139+
}
140+
}
95141
}
96142

97143
@Test

‎src/test/java/inra/ijpb/label/distmap/ChamferDistanceTransform3DShortTest.java‎

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
*/
3838
public class ChamferDistanceTransform3DShortTest
3939
{
40-
4140
/**
4241
* Test method for {@link inra.ijpb.label.distmap.ChamferDistanceTransform3DShort#distanceMap(ij.ImageStack)}.
4342
*/
@@ -71,29 +70,74 @@ public void test_distanceMap_Borgefors()
7170
* Test method for {@link inra.ijpb.label.distmap.ChamferDistanceTransform3DShort#distanceMap(ij.ImageStack)}.
7271
*/
7372
@Test
74-
public void test_distanceMap_Svensson()
73+
public void test_distanceMap_Svensson_sameAsBorgefors()
7574
{
7675
// create 3D image containing a cube
77-
ImageStack image = ImageStack.create(20, 20, 20, 8);
78-
for (int z = 2; z < 19; z++)
76+
ImageStack image = TestImages.createStack_eightCuboids();
77+
78+
ChamferMask3D mask0 = ChamferMask3D.BORGEFORS;
79+
DistanceTransform3D refAlgo = new ChamferDistanceTransform3DShort(mask0, true);
80+
ImageStack ref = refAlgo.distanceMap(image);
81+
82+
ChamferMask3D mask = ChamferMask3D.SVENSSON_3_4_5_7;
83+
DistanceTransform3D algo = new ChamferDistanceTransform3DShort(mask, true);
84+
85+
ImageStack result = algo.distanceMap(image);
86+
87+
assertEquals(16, result.getBitDepth());
88+
assertEquals(image.getWidth(), result.getWidth());
89+
assertEquals(image.getHeight(), result.getHeight());
90+
assertEquals(image.getSize(), result.getSize());
91+
92+
for (int z = 0; z < result.getSize(); z++)
7993
{
80-
for (int y = 2; y < 19; y++)
94+
for (int y = 0; y < result.getHeight(); y++)
8195
{
82-
for (int x = 2; x < 19; x++)
96+
for (int x = 0; x < result.getWidth(); x++)
8397
{
84-
image.setVoxel(x, y, z, 255);
98+
double refValue = ref.getVoxel(x, y, z);
99+
double value = result.getVoxel(x, y, z);
100+
assertEquals(refValue, value, 0.01);
85101
}
86102
}
87103
}
104+
}
105+
106+
/**
107+
* Test method for {@link inra.ijpb.label.distmap.ChamferDistanceTransform3DShort#distanceMap(ij.ImageStack)}.
108+
*/
109+
@Test
110+
public void test_distanceMap_Svensson_adjacentCubes_sameAsBorgefors()
111+
{
112+
// create 3D image containing a cube
113+
ImageStack image = TestImages.createStack_eightAdjacentCubes();
114+
115+
ChamferMask3D mask0 = ChamferMask3D.BORGEFORS;
116+
DistanceTransform3D refAlgo = new ChamferDistanceTransform3DShort(mask0, true);
117+
ImageStack ref = refAlgo.distanceMap(image);
88118

89119
ChamferMask3D mask = ChamferMask3D.SVENSSON_3_4_5_7;
90120
DistanceTransform3D algo = new ChamferDistanceTransform3DShort(mask, true);
91121

92122
ImageStack result = algo.distanceMap(image);
123+
93124
assertEquals(16, result.getBitDepth());
125+
assertEquals(image.getWidth(), result.getWidth());
126+
assertEquals(image.getHeight(), result.getHeight());
127+
assertEquals(image.getSize(), result.getSize());
94128

95-
double middle = result.getVoxel(10, 10, 10);
96-
assertEquals(9, middle, .1);
129+
for (int z = 0; z < result.getSize(); z++)
130+
{
131+
for (int y = 0; y < result.getHeight(); y++)
132+
{
133+
for (int x = 0; x < result.getWidth(); x++)
134+
{
135+
double refValue = ref.getVoxel(x, y, z);
136+
double value = result.getVoxel(x, y, z);
137+
assertEquals(refValue, value, 0.01);
138+
}
139+
}
140+
}
97141
}
98142

99143
@Test
@@ -186,5 +230,4 @@ public void testDistanceMap_Labels()
186230
assertEquals(1, result.getVoxel(3, 4, 4), .1);
187231
assertEquals(1, result.getVoxel(4, 4, 4), .1);
188232
}
189-
190233
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
*
3+
*/
4+
package inra.ijpb.label.distmap;
5+
6+
import ij.ImageStack;
7+
import inra.ijpb.data.image.ImageUtils;
8+
9+
/**
10+
* A collection of static method for creating test images shared by different
11+
* test cases.
12+
*/
13+
public class TestImages
14+
{
15+
/**
16+
* Creates a test image composed of eight cuboids with various sizes.
17+
*
18+
* @return a test image composed of eight cuboids with various sizes.
19+
*/
20+
public static final ImageStack createStack_eightCuboids()
21+
{
22+
ImageStack stack = ImageStack.create(15, 15, 15, 8);
23+
ImageUtils.fillRect3d(stack, 1, 1, 1, 3, 3, 3, 3);
24+
ImageUtils.fillRect3d(stack, 5, 1, 1, 9, 3, 3, 4);
25+
ImageUtils.fillRect3d(stack, 1, 5, 1, 3, 9, 3, 7);
26+
ImageUtils.fillRect3d(stack, 5, 5, 1, 9, 9, 3, 8);
27+
ImageUtils.fillRect3d(stack, 1, 1, 5, 3, 3, 9, 11);
28+
ImageUtils.fillRect3d(stack, 5, 1, 5, 9, 3, 9, 12);
29+
ImageUtils.fillRect3d(stack, 1, 5, 5, 3, 9, 9, 15);
30+
ImageUtils.fillRect3d(stack, 5, 5, 5, 9, 9, 9, 17);
31+
32+
return stack;
33+
}
34+
35+
/**
36+
* Creates a test image composed of eight adjacent cubes that also touch the
37+
* image borders.
38+
*
39+
* @return a test image composed of eight adjacent cubes.
40+
*/
41+
public static final ImageStack createStack_eightAdjacentCubes()
42+
{
43+
ImageStack stack = ImageStack.create(10, 10, 10, 8);
44+
ImageUtils.fillRect3d(stack, 0, 0, 0, 5, 5, 5, 3);
45+
ImageUtils.fillRect3d(stack, 5, 0, 0, 5, 5, 5, 4);
46+
ImageUtils.fillRect3d(stack, 0, 5, 0, 5, 5, 5, 7);
47+
ImageUtils.fillRect3d(stack, 5, 5, 0, 5, 5, 5, 8);
48+
ImageUtils.fillRect3d(stack, 0, 0, 5, 5, 5, 5, 11);
49+
ImageUtils.fillRect3d(stack, 5, 0, 5, 5, 5, 5, 12);
50+
ImageUtils.fillRect3d(stack, 0, 5, 5, 5, 5, 5, 15);
51+
ImageUtils.fillRect3d(stack, 5, 5, 5, 5, 5, 5, 17);
52+
53+
return stack;
54+
}
55+
56+
/**
57+
* private constructor to prevent instantiation.
58+
*/
59+
private TestImages()
60+
{
61+
}
62+
}

0 commit comments

Comments
 (0)