Skip to content

Commit 9670b15

Browse files
committed
Merge branch 'develop'
2 parents b44852a + 0d804e3 commit 9670b15

File tree

5 files changed

+126
-97
lines changed

5 files changed

+126
-97
lines changed

.classpath

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="src" output="target/classes" path="src/main/java">
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
44
<attributes>
5-
<attribute name="optional" value="true"/>
65
<attribute name="maven.pomderived" value="true"/>
76
</attributes>
87
</classpathentry>
9-
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
8+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
109
<attributes>
11-
<attribute name="optional" value="true"/>
1210
<attribute name="maven.pomderived" value="true"/>
13-
<attribute name="test" value="true"/>
1411
</attributes>
1512
</classpathentry>
16-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
13+
<classpathentry kind="src" path=".apt_generated">
1714
<attributes>
18-
<attribute name="maven.pomderived" value="true"/>
15+
<attribute name="optional" value="true"/>
1916
</attributes>
2017
</classpathentry>
21-
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
18+
<classpathentry kind="src" output="target/test-classes" path=".apt_generated_tests">
19+
<attributes>
20+
<attribute name="optional" value="true"/>
21+
<attribute name="test" value="true"/>
22+
</attributes>
23+
</classpathentry>
24+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
2225
<attributes>
2326
<attribute name="maven.pomderived" value="true"/>
2427
</attributes>
2528
</classpathentry>
26-
<classpathentry kind="src" path=".apt_generated">
29+
<classpathentry kind="src" output="target/classes" path="src/main/java">
2730
<attributes>
2831
<attribute name="optional" value="true"/>
32+
<attribute name="maven.pomderived" value="true"/>
2933
</attributes>
3034
</classpathentry>
31-
<classpathentry kind="src" output="target/test-classes" path=".apt_generated_tests">
35+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
3236
<attributes>
3337
<attribute name="optional" value="true"/>
38+
<attribute name="maven.pomderived" value="true"/>
3439
<attribute name="test" value="true"/>
3540
</attributes>
3641
</classpathentry>

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"java.configuration.updateBuildConfiguration": "automatic"
2+
"java.configuration.updateBuildConfiguration": "automatic",
3+
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m"
34
}

pom.xml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<artifactId>MIA_DeepLearning</artifactId>
77
<groupId>io.github.mianalysis</groupId>
8-
<version>1.0.2</version>
8+
<version>1.1.0</version>
99
<packaging>jar</packaging>
1010

1111
<properties>
@@ -45,14 +45,28 @@
4545
<scope>${scp}</scope>
4646
</dependency>
4747

48+
<dependency>
49+
<groupId>ome</groupId>
50+
<artifactId>formats-bsd</artifactId>
51+
<version>LATEST</version>
52+
<scope>${scp}</scope>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>net.imagej</groupId>
57+
<artifactId>ij</artifactId>
58+
<version>LATEST</version>
59+
<scope>${scp}</scope>
60+
</dependency>
61+
4862
<dependency>
4963
<groupId>com.github.mianalysis</groupId>
5064
<artifactId>mia</artifactId>
51-
<version>v1.0.0</version>
65+
<version>v1.1.0</version>
5266
<scope>${scp}</scope>
5367
<!-- <groupId>io.github.mianalysis</groupId>
5468
<artifactId>mia</artifactId>
55-
<version>0.21.3</version>
69+
<version>1.1.0-SNAPSHOT</version>
5670
<scope>${scp}</scope> -->
5771
</dependency>
5872
</dependencies>

src/main/java/io/github/mianalysis/mia_deeplearning/module/StarDistDetection.java

Lines changed: 91 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import java.util.concurrent.Future;
1212
import java.util.stream.IntStream;
1313

14-
import com.drew.lang.annotations.Nullable;
15-
14+
import org.jetbrains.annotations.Nullable;
1615
import org.scijava.Context;
1716
import org.scijava.Priority;
1817
import org.scijava.command.CommandModule;
@@ -30,11 +29,10 @@
3029
import io.github.mianalysis.mia.module.Module;
3130
import io.github.mianalysis.mia.module.Modules;
3231
import io.github.mianalysis.mia.module.images.transform.ExtractSubstack;
33-
import io.github.mianalysis.mia.object.Image;
3432
import io.github.mianalysis.mia.object.Obj;
3533
import io.github.mianalysis.mia.object.Objs;
36-
import io.github.mianalysis.mia.object.Status;
3734
import io.github.mianalysis.mia.object.Workspace;
35+
import io.github.mianalysis.mia.object.image.Image;
3836
import io.github.mianalysis.mia.object.parameters.BooleanP;
3937
import io.github.mianalysis.mia.object.parameters.ChoiceP;
4038
import io.github.mianalysis.mia.object.parameters.FilePathP;
@@ -49,6 +47,7 @@
4947
import io.github.mianalysis.mia.object.refs.collections.ObjMeasurementRefs;
5048
import io.github.mianalysis.mia.object.refs.collections.ParentChildRefs;
5149
import io.github.mianalysis.mia.object.refs.collections.PartnerRefs;
50+
import io.github.mianalysis.mia.object.system.Status;
5251
import io.github.mianalysis.mia.object.units.TemporalUnit;
5352
import io.github.sjcross.sjcommon.exceptions.IntegerOverflowException;
5453
import io.github.sjcross.sjcommon.object.volume.SpatCal;
@@ -143,38 +142,38 @@ public String getDescription() {
143142
return "Implements the StarDist plugin to detect objects. For more information on StarDist please see <a href=\"https://imagej.net/plugins/stardist\">https://imagej.net/plugins/stardist</a>.";
144143
}
145144

146-
File getModelFile(@Nullable HashMap<String, Object> paramsCNN) {
147-
switch ((String) parameters.getValue(MODEL_MODE)) {
148-
case ModelModes.FROM_FILE:
149-
return new File((String) parameters.getValue(MODEL_PATH));
150-
151-
case ModelModes.PRE_DEFINED:
152-
StarDist2DModel model = null;
153-
switch ((String) parameters.getValue(MODEL_NAME)) {
154-
case ModelNames.DSB_2018:
155-
model = MODELS.get(MODEL_DSB2018_PAPER);
156-
break;
157-
case ModelNames.VERSATILE_FLUORESCENT_NUCLEI:
158-
model = MODELS.get(MODEL_DSB2018_HEAVY_AUGMENTATION);
159-
break;
160-
case ModelNames.VERSATILE_HE_NUCLEI:
161-
model = MODELS.get(MODEL_HE_HEAVY_AUGMENTATION);
162-
break;
163-
}
145+
File getModelFile(@Nullable HashMap<String, Object> paramsCNN, Workspace workspace) {
146+
switch ((String) parameters.getValue(MODEL_MODE,workspace)) {
147+
case ModelModes.FROM_FILE:
148+
return new File((String) parameters.getValue(MODEL_PATH,workspace));
149+
150+
case ModelModes.PRE_DEFINED:
151+
StarDist2DModel model = null;
152+
switch ((String) parameters.getValue(MODEL_NAME,workspace)) {
153+
case ModelNames.DSB_2018:
154+
model = MODELS.get(MODEL_DSB2018_PAPER);
155+
break;
156+
case ModelNames.VERSATILE_FLUORESCENT_NUCLEI:
157+
model = MODELS.get(MODEL_DSB2018_HEAVY_AUGMENTATION);
158+
break;
159+
case ModelNames.VERSATILE_HE_NUCLEI:
160+
model = MODELS.get(MODEL_HE_HEAVY_AUGMENTATION);
161+
break;
162+
}
164163

165-
if (model.canGetFile()) {
166-
try {
167-
paramsCNN.put("blockMultiple", model.sizeDivBy);
168-
paramsCNN.put("overlap", model.tileOverlap);
169-
return model.getFile();
170-
} catch (IOException e) {
164+
if (model.canGetFile()) {
165+
try {
166+
paramsCNN.put("blockMultiple", model.sizeDivBy);
167+
paramsCNN.put("overlap", model.tileOverlap);
168+
return model.getFile();
169+
} catch (IOException e) {
170+
MIA.log.writeWarning("Can't get StarDist model");
171+
return null;
172+
}
173+
} else {
171174
MIA.log.writeWarning("Can't get StarDist model");
172175
return null;
173176
}
174-
} else {
175-
MIA.log.writeWarning("Can't get StarDist model");
176-
return null;
177-
}
178177
}
179178

180179
return null;
@@ -209,80 +208,89 @@ Pair<Dataset, Dataset> splitPrediction(final Dataset prediction, final DatasetSe
209208
@Override
210209
protected Status process(Workspace workspace) {
211210
// Getting input image
212-
String inputImageName = parameters.getValue(INPUT_IMAGE);
211+
String inputImageName = parameters.getValue(INPUT_IMAGE,workspace);
212+
String outputObjectsName = parameters.getValue(OUTPUT_OBJECTS,workspace);
213+
213214
Image image = workspace.getImages().get(inputImageName);
214215
ImagePlus ipl = image.getImagePlus();
215216
SpatCal cal = SpatCal.getFromImage(ipl);
216217
int nFrames = ipl.getNFrames();
217218
double frameInterval = ipl.getCalibration().frameInterval;
218219

219-
// Creating output object collection
220-
String outputObjectsName = parameters.getValue(OUTPUT_OBJECTS);
220+
// Creating output object collection
221221
Objs outputObjects = new Objs(outputObjectsName, cal, nFrames, frameInterval, TemporalUnit.getOMEUnit());
222222

223223
ImageJ ij = new ImageJ();
224224
Context context = MIA.ijService.context();
225225
DatasetService datasetService = (DatasetService) MIA.ijService.context().service("net.imagej.DatasetService");
226-
226+
227227
// Initialising parameter sets
228228
HashMap<String, Object> paramsCNN = new HashMap<>();
229-
paramsCNN.put("normalizeInput", parameters.getValue(NORMALISE_INPUT));
230-
paramsCNN.put("percentileBottom", parameters.getValue(PERCENTILE_LOW));
231-
paramsCNN.put("percentileTop", parameters.getValue(PERCENTILE_HIGH));
229+
paramsCNN.put("normalizeInput", parameters.getValue(NORMALISE_INPUT,workspace));
230+
paramsCNN.put("percentileBottom", parameters.getValue(PERCENTILE_LOW,workspace));
231+
paramsCNN.put("percentileTop", parameters.getValue(PERCENTILE_HIGH,workspace));
232232
paramsCNN.put("clip", false);
233-
paramsCNN.put("nTiles", parameters.getValue(NUMBER_OF_TILES));
233+
paramsCNN.put("nTiles", parameters.getValue(NUMBER_OF_TILES,workspace));
234234
paramsCNN.put("blockMultiple", 64);
235235
paramsCNN.put("overlap", 64);
236236
paramsCNN.put("batchSize", 1);
237237
paramsCNN.put("showProgressDialog", false);
238238

239-
File modelFile = getModelFile(paramsCNN);
239+
File modelFile = getModelFile(paramsCNN,workspace);
240240
if (modelFile == null)
241241
return Status.FAIL;
242242
paramsCNN.put("modelFile", modelFile);
243243

244244
HashMap<String, Object> paramsNMS = new HashMap<>();
245-
paramsNMS.put("probThresh", parameters.getValue(PROB_THRESHOLD));
246-
paramsNMS.put("nmsThresh", parameters.getValue(OVERLAP_THRESHOLD));
247-
paramsNMS.put("excludeBoundary", parameters.getValue(BOUNDARY_EXCLUSION));
245+
paramsNMS.put("probThresh", parameters.getValue(PROB_THRESHOLD,workspace));
246+
paramsNMS.put("nmsThresh", parameters.getValue(OVERLAP_THRESHOLD,workspace));
247+
paramsNMS.put("excludeBoundary", parameters.getValue(BOUNDARY_EXCLUSION,workspace));
248248
paramsNMS.put("roiPosition", Opt.ROI_POSITION_STACK);
249249
paramsNMS.put("verbose", false);
250250
paramsNMS.put("outputType", Opt.OUTPUT_POLYGONS);
251251

252-
for (int z = 0; z < ipl.getNSlices(); z++) {
253-
Module.writeProgressStatus((z + 1), ipl.getNSlices(), "slices", "StarDist");
254-
255-
Image subs = ExtractSubstack.extractSubstack(image, "Subs", "1", String.valueOf(z + 1), "1");
256-
ImgPlus img = subs.getImgPlus();
257-
DefaultDataset dataset = new DefaultDataset(context, img);
258-
paramsCNN.put("input", dataset);
259-
260-
try {
261-
Future<CommandModule> futureCNN = ij.command().run(de.csbdresden.csbdeep.commands.GenericNetwork.class,
262-
false, paramsCNN);
263-
Dataset prediction = (Dataset) futureCNN.get().getOutput("output");
264-
265-
Pair<Dataset, Dataset> probAndDist = splitPrediction(prediction, datasetService);
266-
Dataset probDS = probAndDist.getA();
267-
Dataset distDS = probAndDist.getB();
268-
paramsNMS.put("prob", probDS);
269-
paramsNMS.put("dist", distDS);
270-
271-
Future<CommandModule> futureNMS = ij.command().run(de.csbdresden.stardist.StarDist2DNMS.class, false,
272-
paramsNMS);
273-
Candidates polygons = (Candidates) futureNMS.get().getOutput("polygons");
274-
List<Integer> indices = polygons.getWinner();
275-
276-
for (Integer idx : indices) {
277-
PolygonRoi polygon = polygons.getPolygonRoi(idx);
278-
Obj obj = outputObjects.createAndAddNewObject(VolumeType.QUADTREE);
279-
try {
280-
obj.addPointsFromRoi(polygon, z);
281-
} catch (IntegerOverflowException e) {
252+
int count = 0;
253+
int total = ipl.getNFrames()*ipl.getNSlices();
254+
for (int t = 0; t < ipl.getNFrames(); t++) {
255+
for (int z = 0; z < ipl.getNSlices(); z++) {
256+
Image subs = ExtractSubstack.extractSubstack(image, "Subs", "1-end", String.valueOf(z + 1), String.valueOf(t + 1));
257+
ImgPlus img = subs.getImgPlus();
258+
DefaultDataset dataset = new DefaultDataset(context, img);
259+
paramsCNN.put("input", dataset);
260+
261+
try {
262+
Future<CommandModule> futureCNN = ij.command().run(
263+
de.csbdresden.csbdeep.commands.GenericNetwork.class,
264+
false, paramsCNN);
265+
Dataset prediction = (Dataset) futureCNN.get().getOutput("output");
266+
267+
Pair<Dataset, Dataset> probAndDist = splitPrediction(prediction, datasetService);
268+
Dataset probDS = probAndDist.getA();
269+
Dataset distDS = probAndDist.getB();
270+
paramsNMS.put("prob", probDS);
271+
paramsNMS.put("dist", distDS);
272+
273+
Future<CommandModule> futureNMS = ij.command().run(de.csbdresden.stardist.StarDist2DNMS.class,
274+
false,
275+
paramsNMS);
276+
Candidates polygons = (Candidates) futureNMS.get().getOutput("polygons");
277+
List<Integer> indices = polygons.getWinner();
278+
279+
for (Integer idx : indices) {
280+
PolygonRoi polygon = polygons.getPolygonRoi(idx);
281+
Obj obj = outputObjects.createAndAddNewObject(VolumeType.QUADTREE);
282+
try {
283+
obj.addPointsFromRoi(polygon, z);
284+
} catch (IntegerOverflowException e) {
285+
}
286+
obj.setT(t);
282287
}
288+
} catch (InterruptedException | ExecutionException e) {
289+
return Status.FAIL;
283290
}
284-
} catch (InterruptedException | ExecutionException e) {
285-
return Status.FAIL;
291+
292+
Module.writeProgressStatus(++count, total, "slices", "StarDist");
293+
286294
}
287295
}
288296

@@ -329,13 +337,13 @@ public Parameters updateAndGetParameters() {
329337

330338
returnedParameters.add(parameters.getParameter(MODEL_SEPARATOR));
331339
returnedParameters.add(parameters.getParameter(MODEL_MODE));
332-
switch ((String) parameters.getValue(MODEL_MODE)) {
333-
case ModelModes.FROM_FILE:
334-
returnedParameters.add(parameters.getParameter(MODEL_PATH));
335-
break;
336-
case ModelModes.PRE_DEFINED:
337-
returnedParameters.add(parameters.getParameter(MODEL_NAME));
338-
break;
340+
switch ((String) parameters.getValue(MODEL_MODE,null)) {
341+
case ModelModes.FROM_FILE:
342+
returnedParameters.add(parameters.getParameter(MODEL_PATH));
343+
break;
344+
case ModelModes.PRE_DEFINED:
345+
returnedParameters.add(parameters.getParameter(MODEL_NAME));
346+
break;
339347
}
340348

341349
returnedParameters.add(parameters.getParameter(PREDICTION_SEPARATOR));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"class":"io.github.mianalysis.mia_deeplearning.moduledependencies.StarDistDetectionDependency","values":{"priority":-100.0,"type":"io.github.mianalysis.mia.moduledependencies.Dependency","visible":true}}{"class":"io.github.mianalysis.mia_deeplearning.module.StarDistDetection","values":{"priority":-100.0,"type":"io.github.mianalysis.mia.module.Module","visible":true}}

0 commit comments

Comments
 (0)