Skip to content

Commit 007aeaa

Browse files
authored
Merge pull request #212 from mianalysis/develop
Develop
2 parents bbef089 + 4d3bc8a commit 007aeaa

File tree

35 files changed

+1818
-383
lines changed

35 files changed

+1818
-383
lines changed

.vscode/launch.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"configurations": [
3+
{
4+
"type": "java",
5+
"name": "ApplySegmentAnything",
6+
"request": "launch",
7+
"mainClass": "io.github.mianalysis.mia.module.objects.detect.ApplySegmentAnything",
8+
"projectName": "mia-samj"
9+
},
310
{
411
"type": "java",
512
"name": "Folder",

mia-algorithms/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<parent>
77
<groupId>io.github.mianalysis</groupId>
88
<artifactId>pom-mia</artifactId>
9-
<version>1.7.0</version>
9+
<version>1.7.1</version>
1010
</parent>
1111

1212
<groupId>io.github.mianalysis</groupId>
1313
<artifactId>mia-algorithms</artifactId>
14-
<version>1.7.0</version>
14+
<version>1.7.1</version>
1515
<packaging>jar</packaging>
1616
<name>mia-algorithms</name>
1717
<url>https://github.com/mianalysis/mia</url>

mia-algorithms/src/main/java/io/github/mianalysis/mia/process/analysis/CurvatureCalculator.java

Lines changed: 68 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Created by sc13967 on 26/01/2018.
1919
*/
2020
public class CurvatureCalculator {
21-
private ArrayList<Point<Integer>> path;
21+
private ArrayList<Point<Double>> path;
2222
private PolynomialSplineFunction[] splines = null;
2323
private TreeMap<Double, Double> curvature = null;
2424
private FittingMethod fittingMethod = FittingMethod.STANDARD;
@@ -32,91 +32,113 @@ public enum FittingMethod {
3232
private double loessBandwidth = 0.04;
3333
private int loessIterations = 0;
3434
private double loessAccuracy = 100;
35+
private boolean is2D = true;
3536

36-
public CurvatureCalculator(ArrayList<Point<Integer>> path, boolean isLoop) {
37+
public CurvatureCalculator(ArrayList<Point<Double>> path, boolean isLoop, boolean is2D) {
3738
this.path = path;
3839
this.isLoop = isLoop;
39-
40+
this.is2D = is2D;
4041
}
4142

4243
public void calculateCurvature() {
4344
// Checking there are enough points for fitting
4445
int nKnots = path.size();
4546
if (nKnots < (NNeighbours + 1))
46-
return;
47-
47+
return;
48+
4849
if (isLoop)
4950
nKnots = nKnots + 2 * NNeighbours;
5051

5152
// Preparing line coordinates for spline fitting
5253
double[] t = new double[nKnots];
5354
double[] x = new double[nKnots];
5455
double[] y = new double[nKnots];
56+
double[] z = new double[nKnots]; // Always defining this to please the linter
5557

5658
int count = 0;
57-
Point<Integer> prevVertex = null;
59+
Point<Double> prevVertex = null;
5860

5961
// If a loop, starting with the final few points from the opposite end
6062
if (isLoop) {
6163
int len = path.size();
6264
for (int i = NNeighbours; i > 0; i--) {
63-
Point<Integer> vertex = path.get((len - i));
65+
Point<Double> vertex = path.get((len - i));
6466
t[count] = count == 0 ? 0 : t[count - 1] + vertex.calculateDistanceToPoint(prevVertex);
6567
x[count] = vertex.getX();
66-
y[count++] = vertex.getY();
68+
y[count] = vertex.getY();
69+
70+
if (!is2D)
71+
z[count] = vertex.getZ();
72+
73+
count++;
6774

6875
prevVertex = vertex;
6976

7077
}
7178
}
7279

73-
for (Point<Integer> vertex : path) {
80+
for (Point<Double> vertex : path) {
7481
t[count] = count == 0 ? 0 : t[count - 1] + vertex.calculateDistanceToPoint(prevVertex);
7582
x[count] = vertex.getX();
76-
y[count++] = vertex.getY();
83+
y[count] = vertex.getY();
84+
85+
if (!is2D)
86+
z[count] = vertex.getZ();
87+
88+
count++;
7789

7890
prevVertex = vertex;
7991

8092
}
81-
93+
8294
// If a loop, ending with the first few points from the opposite end
8395
if (isLoop) {
8496
for (int i = 0; i < NNeighbours; i++) {
85-
Point<Integer> vertex = path.get(i);
97+
Point<Double> vertex = path.get(i);
8698
t[count] = count == 0 ? 0 : t[count - 1] + vertex.calculateDistanceToPoint(prevVertex);
8799
x[count] = vertex.getX();
88-
y[count++] = vertex.getY();
100+
y[count] = vertex.getY();
101+
102+
if (!is2D)
103+
z[count] = vertex.getZ();
104+
105+
count++;
89106

90107
prevVertex = vertex;
91108

92109
}
93110
}
94111

95-
// Storing splines
96-
splines = new PolynomialSplineFunction[6];
112+
// Storing splines x, dx, y, dy, z, dz
113+
splines = is2D ? new PolynomialSplineFunction[4] : new PolynomialSplineFunction[6];
97114

98115
// Fitting the spline pair
99116
switch (fittingMethod) {
100117
case LOESS:
101118
LoessInterpolator loessInterpolator = new LoessInterpolator(loessBandwidth, loessIterations,
102119
loessAccuracy);
103120
splines[0] = loessInterpolator.interpolate(t, x);
104-
splines[1] = loessInterpolator.interpolate(t, y);
121+
splines[2] = loessInterpolator.interpolate(t, y);
122+
123+
if (!is2D)
124+
splines[4] = loessInterpolator.interpolate(t, z);
105125
break;
106126

107127
case STANDARD:
108128
SplineInterpolator splineInterpolator = new SplineInterpolator();
109129
splines[0] = splineInterpolator.interpolate(t, x);
110-
splines[1] = splineInterpolator.interpolate(t, y);
130+
splines[2] = splineInterpolator.interpolate(t, y);
131+
if (!is2D)
132+
splines[4] = splineInterpolator.interpolate(t, z);
111133
break;
112134
}
113135

114136
// Calculating curvature
115-
splines[2] = splines[0].polynomialSplineDerivative(); // dx
116-
splines[3] = splines[2].polynomialSplineDerivative(); // ddx
117-
splines[4] = splines[1].polynomialSplineDerivative(); // dy
118-
splines[5] = splines[4].polynomialSplineDerivative(); // ddy
119-
137+
splines[1] = splines[0].polynomialSplineDerivative(); // dx
138+
splines[3] = splines[2].polynomialSplineDerivative(); // dy
139+
if (!is2D)
140+
splines[5] = splines[4].polynomialSplineDerivative(); // dz
141+
120142
// Extracting the gradients as a function of position along the curve
121143
double[] knots = splines[0].getKnots();
122144

@@ -132,11 +154,21 @@ public void calculateCurvature() {
132154
double width = maxPos - minPos;
133155

134156
double dx = (splines[0].value(maxPos) - splines[0].value(minPos)) / width;
135-
double dy = (splines[1].value(maxPos) - splines[1].value(minPos)) / width;
136-
double ddx = (splines[2].value(maxPos) - splines[2].value(minPos)) / (0.5 * width);
137-
double ddy = (splines[3].value(maxPos) - splines[3].value(minPos)) / (0.5 * width);
138-
139-
double k = (dx * ddy - dy * ddx) / Math.pow((dx * dx + dy * dy), 3d / 2d);
157+
double ddx = (splines[1].value(maxPos) - splines[1].value(minPos)) / width;
158+
double dy = (splines[2].value(maxPos) - splines[2].value(minPos)) / width;
159+
double ddy = (splines[3].value(maxPos) - splines[3].value(minPos)) / width;
160+
161+
double k;
162+
if (is2D) {
163+
k = (dx * ddy - dy * ddx) / Math.pow((dx * dx + dy * dy), 3d / 2d);
164+
} else {
165+
double dz = (splines[4].value(maxPos) - splines[4].value(minPos)) / width;
166+
double ddz = (splines[5].value(maxPos) - splines[5].value(minPos)) / width;
167+
double term1 = (ddz * dy - ddy * dz) * (ddz * dy - ddy * dz);
168+
double term2 = (ddx * dz - ddz * dx) * (ddx * dz - ddz * dx);
169+
double term3 = (ddy * dx - ddx * dy) * (ddy * dx - ddx * dy);
170+
k = Math.sqrt(term1 + term2 + term3) / Math.pow((dx * dx + dy * dy + dz * dz), 3d / 2d);
171+
}
140172

141173
curvature.put(knots[i], k);
142174

@@ -190,9 +222,9 @@ public void showOverlay(ImagePlus ipl, double maxCurvature, int[] position, doub
190222
p2 = iterator.next();
191223

192224
double x1 = splines[0].value(p1);
193-
double y1 = splines[1].value(p1);
225+
double y1 = splines[2].value(p1);
194226
double x2 = splines[0].value(p2);
195-
double y2 = splines[1].value(p2);
227+
double y2 = splines[2].value(p2);
196228

197229
double k1 = Math.abs(curvature.get(p1));
198230
double k2 = Math.abs(curvature.get(p2));
@@ -258,22 +290,23 @@ public void setFittingMethod(FittingMethod fittingMethod) {
258290
this.fittingMethod = fittingMethod;
259291
}
260292

261-
public ArrayList<Point<Integer>> getSpline() {
293+
public TreeMap<Point<Double>,Double> getSpline() {
262294
if (splines == null)
263295
calculateCurvature();
264296

265-
ArrayList<Point<Integer>> spline = new ArrayList<>();
297+
TreeMap<Point<Double>,Double> spline = new TreeMap<>();
266298

267299
double[] knots = splines[0].getKnots();
268300
int startIdx = isLoop ? NNeighbours : 0;
269301
int endIdx = isLoop ? knots.length - NNeighbours : knots.length;
270302
for (int i = startIdx; i < endIdx; i++) {
271303
double t = knots[i];
272-
273-
int x = (int) Math.round(splines[0].value(t));
274-
int y = (int) Math.round(splines[1].value(t));
275304

276-
spline.add(new Point<Integer>(x, y, 0));
305+
double x = splines[0].value(t);
306+
double y = splines[2].value(t);
307+
double z = is2D ? 0d : splines[4].value(t);
308+
309+
spline.put(new Point<Double>(x, y, z),curvature.get(t));
277310

278311
}
279312

mia-bonej/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<parent>
77
<groupId>io.github.mianalysis</groupId>
88
<artifactId>pom-mia</artifactId>
9-
<version>1.7.0</version>
9+
<version>1.7.1</version>
1010
</parent>
1111

1212
<groupId>io.github.mianalysis</groupId>
1313
<artifactId>mia-bonej</artifactId>
14-
<version>1.7.0</version>
14+
<version>1.7.1</version>
1515
<packaging>jar</packaging>
1616
<name>mia-bonej</name>
1717
<url>https://github.com/mianalysis/mia</url>

mia-coordinates/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<parent>
77
<groupId>io.github.mianalysis</groupId>
88
<artifactId>pom-mia</artifactId>
9-
<version>1.7.0</version>
9+
<version>1.7.1</version>
1010
</parent>
1111

1212
<groupId>io.github.mianalysis</groupId>
1313
<artifactId>mia-coordinates</artifactId>
14-
<version>1.7.0</version>
14+
<version>1.7.1</version>
1515
<packaging>jar</packaging>
1616
<name>mia-coordinates</name>
1717
<url>https://github.com/mianalysis/mia</url>

mia-core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<parent>
77
<groupId>io.github.mianalysis</groupId>
88
<artifactId>pom-mia</artifactId>
9-
<version>1.7.0</version>
9+
<version>1.7.1</version>
1010
</parent>
1111

1212
<groupId>io.github.mianalysis</groupId>
1313
<artifactId>mia-core</artifactId>
14-
<version>1.7.0</version>
14+
<version>1.7.1</version>
1515
<packaging>jar</packaging>
1616
<name>mia-core</name>
1717
<url>https://github.com/mianalysis/mia</url>

mia-core/src/main/java/io/github/mianalysis/mia/MIA.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.scijava.plugin.PluginService;
1414
import org.scijava.script.ScriptService;
1515

16+
import com.fasterxml.jackson.core.util.VersionUtil;
17+
1618
import io.github.mianalysis.mia.module.lostandfound.LostAndFound;
1719
import io.github.mianalysis.mia.moduledependencies.Dependencies;
1820
import io.github.mianalysis.mia.object.system.Preferences;
@@ -69,7 +71,7 @@ private static String extractVersion() {
6971
} catch (IOException e) {
7072
e.printStackTrace();
7173
return "";
72-
}
74+
}
7375
} else {
7476
return versionNumber;
7577
}

mia-core/src/main/java/io/github/mianalysis/mia/object/Objs.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public String getName() {
104104
}
105105

106106
synchronized public void add(Obj object) {
107+
maxID = Math.max(maxID, object.getID());
107108
put(object.getID(), object);
108109

109110
}
@@ -405,6 +406,10 @@ public void resetCollection() {
405406
maxID = 0;
406407
}
407408

409+
public void recalculateMaxID() {
410+
maxID = getLargestID();
411+
}
412+
408413
/**
409414
* Displays measurement values from a specific Module
410415
*

mia-core/src/main/java/io/github/mianalysis/mia/process/analysishandling/AnalysisRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ Runnable createRunnable(Modules modules, Workspace workspace, Exporter exporter,
346346

347347
MIA.log.writeError(
348348
"Failed for file " + file.getName() + ", series " + seriesNumber + " (" + memoryMessage + ")");
349-
t.printStackTrace();
349+
MIA.log.writeError(t);
350350

351351
workspace.clearAllImages(true);
352352
workspace.clearAllObjects(true);
@@ -413,4 +413,4 @@ String getSeriesName() {
413413
int getFileDepth() {
414414
return fileDepth;
415415
}
416-
}
416+
}

mia-deepimagej/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<parent>
77
<groupId>io.github.mianalysis</groupId>
88
<artifactId>pom-mia</artifactId>
9-
<version>1.7.0</version>
9+
<version>1.7.1</version>
1010
</parent>
1111

1212
<groupId>io.github.mianalysis</groupId>
1313
<artifactId>mia-deepimagej</artifactId>
14-
<version>1.7.0</version>
14+
<version>1.7.1</version>
1515
<packaging>jar</packaging>
1616
<name>mia-deepimagej</name>
1717
<url>https://github.com/mianalysis/mia</url>

0 commit comments

Comments
 (0)