Skip to content

Commit e3cec2f

Browse files
committed
fix computation of average thickness for calibrated images
1 parent c08be60 commit e3cec2f

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

‎src/main/java/inra/ijpb/measure/region2d/AverageThickness.java‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,11 @@ public AverageThickness.Result[] analyzeRegions(ImageProcessor image, int[] labe
133133
}
134134
}
135135

136-
// convert to array of results
136+
// convert to array of (calibrated) results
137137
AverageThickness.Result[] results = new AverageThickness.Result[nLabels];
138138
for (int i = 0; i < nLabels; i++)
139139
{
140-
Result res = new Result();
141-
res.meanDist = calib.pixelWidth * (sums[i] / counts[i]);
142-
res.avgThickness = res.meanDist * 2 - 1;
143-
res.unit = calib.getUnit();
144-
results[i] = res;
140+
results[i] = new Result(sums[i] / counts[i], calib);
145141
}
146142
return results;
147143
}
@@ -160,20 +156,33 @@ public AverageThickness.Result[] analyzeRegions(ImageProcessor image, int[] labe
160156
public class Result
161157
{
162158
/**
163-
* Average distance computed along the skeleton
159+
* Average distance computed along the skeleton, in pixels.
164160
*/
165-
public double meanDist;
161+
public final double meanDist_Pixels;
162+
163+
/**
164+
* Average distance computed along the skeleton, converted in user units.
165+
*/
166+
public final double meanDist;
166167

167168
/**
168169
* Average thickness value computed from the average distance.
169170
* Typically: avgThickness = avgDist * 2 - 1.
170171
*/
171-
public double avgThickness;
172+
public final double avgThickness;
172173

173174
/**
174175
* The unit associated to the measure.
175176
*/
176-
public String unit = "pixel";
177+
public final String unit;
178+
179+
public Result(double meanDistInPixels, Calibration calib)
180+
{
181+
this.meanDist_Pixels = meanDistInPixels;
182+
this.meanDist = calib.pixelWidth * this.meanDist_Pixels;
183+
this.avgThickness = calib.pixelWidth * (this.meanDist_Pixels * 2 - 1);
184+
this.unit = calib.getUnit();
185+
}
177186
}
178187

179188
}

‎src/test/java/inra/ijpb/measure/region2d/AverageThicknessTest.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public final void test_process_rectangle()
6464
assertEquals(1, results.length);
6565

6666
Result res = results[0];
67-
assertTrue(res.meanDist > 2);
68-
assertTrue(res.meanDist <= 3);
67+
assertTrue(res.meanDist_Pixels > 2);
68+
assertTrue(res.meanDist_Pixels <= 3);
6969
}
7070

7171
@Test
@@ -102,8 +102,8 @@ public final void test_process_ThinLines_TouchingLabels()
102102
for (int i = 0; i < labels.length; i++)
103103
{
104104
Result res = results[i];
105-
assertTrue(res.meanDist > 1.5);
106-
assertTrue(res.meanDist < 2.5);
105+
assertTrue(res.meanDist_Pixels > 1.5);
106+
assertTrue(res.meanDist_Pixels < 2.5);
107107
}
108108
}
109109
}

0 commit comments

Comments
 (0)