Skip to content

Commit 8a84e2a

Browse files
committed
Started adding object classification activity
1 parent 503535a commit 8a84e2a

File tree

14 files changed

+240
-36
lines changed

14 files changed

+240
-36
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,25 @@
6262
<dependency>
6363
<groupId>io.github.mianalysis</groupId>
6464
<artifactId>mia-core</artifactId>
65-
<version>1.7.7-SNAPSHOT</version>
65+
<version>1.7.16</version>
6666
</dependency>
6767

6868
<dependency>
6969
<groupId>io.github.mianalysis</groupId>
7070
<artifactId>mia-modules</artifactId>
71-
<version>1.7.7-SNAPSHOT</version>
71+
<version>1.7.16</version>
7272
</dependency>
7373

7474
<dependency>
7575
<groupId>io.github.mianalysis</groupId>
7676
<artifactId>mia-plugin</artifactId>
77-
<version>1.7.7-SNAPSHOT</version>
77+
<version>1.7.16</version>
7878
</dependency>
7979

8080
<dependency>
8181
<groupId>io.github.mianalysis</groupId>
8282
<artifactId>mia-samj</artifactId>
83-
<version>1.7.7-SNAPSHOT</version>
83+
<version>1.7.16</version>
8484
</dependency>
8585

8686
<dependency>

src/main/java/io/github/mianalysis/miaserver/modules/AddPathsToMetadata.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,28 @@ public String getDescription() {
6060

6161
@Override
6262
public Status process(Workspace workspace) {
63+
String workflowPath = modules.getAnalysisFilename();
64+
65+
File workflowFile = new File(workflowPath);
66+
if (!workflowFile.exists())
67+
return Status.PASS;
68+
69+
String workflowName = workflowFile.getName();
70+
if (workflowName.endsWith("mia"))
71+
workflowName = workflowName.substring(0, workflowName.length() - 4);
72+
73+
String miaFolder = workflowFile.getParentFile().getParent();
74+
workspace.getMetadata().put("ImagesPath", miaFolder + "/images/");
75+
workspace.getMetadata().put("ThumbnailsPath", miaFolder + "/thumbnails/");
76+
workspace.getMetadata().put("WorkflowsPath", miaFolder + "/workflows/");
77+
6378
return Status.PASS;
6479

6580
}
6681

6782
@Override
6883
protected void initialiseParameters() {
69-
parameters.add(new MessageP(MESSAGE, this, "This module has no parameters", ParameterState.MESSAGE));
84+
parameters.add(new MessageP(MESSAGE, this, "This module automatically adds the following metadata and global variable values:\r\n - ImagesPath\r\n - ThumbnailsPath\r\n - WorkflowName\r\n - WorkflowPath", ParameterState.MESSAGE,128));
7085
}
7186

7287
@Override

src/main/java/io/github/mianalysis/miaserver/modules/CreateObjectGrid.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.github.mianalysis.mia.module.Module;
88
import io.github.mianalysis.mia.module.Modules;
99
import io.github.mianalysis.mia.object.Obj;
10+
import io.github.mianalysis.mia.object.ObjMetadata;
1011
import io.github.mianalysis.mia.object.Objs;
1112
import io.github.mianalysis.mia.object.Workspace;
1213
import io.github.mianalysis.mia.object.coordinates.volume.PointOutOfRangeException;
@@ -102,6 +103,7 @@ public Status process(Workspace workspace) {
102103
for (int idxX = 0; idxX < nCols; idxX++) {
103104
for (int idxY = 0; idxY < nRows; idxY++) {
104105
Obj outputObj = outputObjects.createAndAddNewObject(VolumeType.QUADTREE);
106+
105107
for (int x = 0; x < cellW; x++) {
106108
for (int y = 0; y < cellH; y++) {
107109
try {

src/main/java/io/github/mianalysis/miaserver/modules/DisplayOverlay.java renamed to src/main/java/io/github/mianalysis/miaserver/modules/DisplayObjects.java

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
import io.github.mianalysis.mia.object.Obj;
1818
import io.github.mianalysis.mia.object.Objs;
1919
import io.github.mianalysis.mia.object.Workspace;
20+
import io.github.mianalysis.mia.object.parameters.ChoiceP;
2021
import io.github.mianalysis.mia.object.parameters.InputObjectsP;
2122
import io.github.mianalysis.mia.object.parameters.Parameters;
2223
import io.github.mianalysis.mia.object.parameters.SeparatorP;
24+
import io.github.mianalysis.mia.object.parameters.text.IntegerP;
2325
import io.github.mianalysis.mia.object.refs.collections.ImageMeasurementRefs;
2426
import io.github.mianalysis.mia.object.refs.collections.MetadataRefs;
2527
import io.github.mianalysis.mia.object.refs.collections.ObjMeasurementRefs;
@@ -34,14 +36,26 @@
3436
import net.imagej.patcher.LegacyInjector;
3537

3638
@Plugin(type = Module.class, priority = Priority.LOW, visible = true)
37-
public class DisplayOverlay extends AbstractOverlay {
39+
public class DisplayObjects extends AbstractOverlay {
3840

3941
public static final String INPUT_SEPARATOR = "Object input";
4042

4143
public static final String INPUT_OBJECTS = "Objects to display";
4244

4345
public static final String RENDERING_SEPARATOR = "Rendering controls";
4446

47+
public static final String RENDERING_MODE = "Rendering mode";
48+
49+
public static final String LINE_WIDTH = "Line width";
50+
51+
public interface RenderingModes {
52+
String FILL = "Fill";
53+
String OUTLINE = "Outline";
54+
55+
String[] ALL = new String[] { FILL, OUTLINE };
56+
57+
}
58+
4559
public interface ColourModes extends AbstractOverlay.ColourModes {
4660
}
4761

@@ -59,11 +73,12 @@ public static void main(String[] args) {
5973
new ImageJ().command().run("io.github.mianalysis.mia.MIA_", false);
6074

6175
// Adding the current module to MIA's list of available modules.
62-
AvailableModules.addModuleName(DisplayOverlay.class);
76+
AvailableModules.addModuleName(DisplayObjects.class);
6377

6478
}
6579

66-
public static JSONObject getOverlayJSON(Objs inputObjects, HashMap<Integer, Color> colours)
80+
public static JSONObject getOverlayJSON(Objs inputObjects, HashMap<Integer, Color> colours, String renderingMode,
81+
int lineWidth)
6782
throws InterruptedException {
6883
JSONObject overlayJSON = new JSONObject();
6984

@@ -78,10 +93,13 @@ public static JSONObject getOverlayJSON(Objs inputObjects, HashMap<Integer, Colo
7893
objectOverlayJSON.put("n", polygon.npoints);
7994

8095
Color colour = colours.get(inputObject.getID());
96+
8197
String hex = String.format("#%02x%02x%02x%02x", colour.getRed(), colour.getGreen(), colour.getBlue(),
8298
colour.getAlpha());
8399
objectOverlayJSON.put("fillcolour", hex);
84100
objectOverlayJSON.put("strokecolour", hex);
101+
objectOverlayJSON.put("renderingmode", renderingMode);
102+
objectOverlayJSON.put("linewidth", String.valueOf(lineWidth));
85103

86104
regionsJSONArray.put(objectOverlayJSON);
87105

@@ -93,7 +111,7 @@ public static JSONObject getOverlayJSON(Objs inputObjects, HashMap<Integer, Colo
93111

94112
}
95113

96-
public DisplayOverlay(Modules modules) {
114+
public DisplayObjects(Modules modules) {
97115
// The first argument is the name by which the module will be seen in the GUI.
98116
super("Display objects", modules);
99117
}
@@ -116,20 +134,22 @@ public String getDescription() {
116134
@Override
117135
public Status process(Workspace workspace) {
118136
String objectsName = parameters.getValue(INPUT_OBJECTS, workspace);
137+
String renderingMode = parameters.getValue(RENDERING_MODE, workspace);
138+
int lineWidth = parameters.getValue(LINE_WIDTH, workspace);
119139

120140
Objs inputObjects = workspace.getObjects(objectsName);
121141

122142
HashMap<Integer, Color> colours = getColours(inputObjects, workspace);
123143

124144
try {
125145
ProcessResult processResult = ProcessResult.getInstance();
126-
JSONObject overlayJSON = getOverlayJSON(inputObjects, colours);
127-
146+
JSONObject overlayJSON = getOverlayJSON(inputObjects, colours, renderingMode, lineWidth);
147+
128148
if (!processResult.has("overlays"))
129149
processResult.put("overlays", new JSONArray());
130150

131151
((JSONArray) processResult.get("overlays")).put(overlayJSON);
132-
152+
133153
} catch (Exception e) {
134154
e.printStackTrace();
135155
}
@@ -148,6 +168,10 @@ protected void initialiseParameters() {
148168
parameters.add(new SeparatorP(INPUT_SEPARATOR, this));
149169
parameters.add(new InputObjectsP(INPUT_OBJECTS, this));
150170

171+
parameters.add(new SeparatorP(RENDERING_SEPARATOR, this));
172+
parameters.add(new ChoiceP(RENDERING_MODE, this, RenderingModes.FILL, RenderingModes.ALL));
173+
parameters.add(new IntegerP(LINE_WIDTH, this, 1));
174+
151175
}
152176

153177
@Override
@@ -157,6 +181,15 @@ public Parameters updateAndGetParameters() {
157181
returnedParameters.add(parameters.getParameter(INPUT_SEPARATOR));
158182
returnedParameters.add(parameters.getParameter(INPUT_OBJECTS));
159183

184+
returnedParameters.add(parameters.getParameter(RENDERING_SEPARATOR));
185+
returnedParameters.add(parameters.getParameter(RENDERING_MODE));
186+
187+
switch ((String) parameters.getValue(RENDERING_MODE, null)) {
188+
case RenderingModes.OUTLINE:
189+
returnedParameters.add(parameters.getParameter(LINE_WIDTH));
190+
break;
191+
}
192+
160193
String inputObjectsName = parameters.getValue(INPUT_OBJECTS, null);
161194
returnedParameters.addAll(super.updateAndGetParameters(inputObjectsName));
162195

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
package io.github.mianalysis.miaserver.modules;
2+
3+
import java.awt.Color;
4+
import java.text.DecimalFormat;
5+
import java.util.HashMap;
6+
7+
import org.json.JSONArray;
8+
import org.json.JSONObject;
9+
10+
import com.drew.lang.annotations.Nullable;
11+
12+
import io.github.mianalysis.mia.MIA;
13+
import io.github.mianalysis.mia.module.Category;
14+
import io.github.mianalysis.mia.module.Modules;
15+
import io.github.mianalysis.mia.module.visualise.overlays.AddLabels;
16+
import io.github.mianalysis.mia.object.Obj;
17+
import io.github.mianalysis.mia.object.Objs;
18+
import io.github.mianalysis.mia.object.Workspace;
19+
import io.github.mianalysis.mia.object.parameters.Parameters;
20+
import io.github.mianalysis.mia.object.system.Status;
21+
import io.github.mianalysis.mia.process.LabelFactory;
22+
import io.github.mianalysis.miaserver.utils.ProcessResult;
23+
24+
public class DisplayText extends AddLabels {
25+
private static final String INPUT_IMAGE = "Input image";
26+
private static final String OUTPUT_SEPARATOR = "Image output";
27+
private static final String APPLY_TO_INPUT = "Apply to input image";
28+
private static final String ADD_OUTPUT_TO_WORKSPACE = "Add output image to workspace";
29+
private static final String OUTPUT_IMAGE = "Output image";
30+
private static final String EXECUTION_SEPARATOR = "Execution controls";
31+
private static final String ENABLE_MULTITHREADING = "Enable multithreading";
32+
33+
public DisplayText(Modules modules) {
34+
super("Display text", modules);
35+
}
36+
37+
@Override
38+
public Category getCategory() {
39+
return io.github.mianalysis.miaserver.ServerCategories.SCHOOLS;
40+
}
41+
42+
@Override
43+
public String getVersionNumber() {
44+
return "1.0.0";
45+
}
46+
47+
@Override
48+
public String getDescription() {
49+
return "Adds an overlay to the specified input image with each object represented by a text label. The label can include information such as measurements, associated object counts or ID numbers.";
50+
}
51+
52+
public static JSONObject getOverlayJSON(Objs inputObjects, HashMap<Integer, String> labels, int labelSize,
53+
HashMap<Integer, Color> colours, String labelPosition, int xOffset, int yOffset, boolean centreText,
54+
@Nullable int[] positions, @Nullable String[] measurementNames) throws InterruptedException {
55+
JSONObject overlayJSON = new JSONObject();
56+
57+
JSONArray regionsJSONArray = new JSONArray();
58+
for (Obj inputObject : inputObjects.values()) {
59+
JSONObject objectOverlayJSON = new JSONObject();
60+
61+
Color colour = colours.get(inputObject.getID());
62+
63+
String hex = String.format("#%02x%02x%02x%02x", colour.getRed(), colour.getGreen(), colour.getBlue(),
64+
colour.getAlpha());
65+
66+
String label = labels == null ? "" : labels.get(inputObject.getID());
67+
double[] location = getLocation(inputObject, labelPosition, xOffset, yOffset, positions, measurementNames);
68+
69+
objectOverlayJSON.put("labelsize", labelSize);
70+
objectOverlayJSON.put("x", location[0]);
71+
objectOverlayJSON.put("y", location[1]);
72+
objectOverlayJSON.put("fillcolour", hex);
73+
objectOverlayJSON.put("strokecolour", hex);
74+
objectOverlayJSON.put("text", label);
75+
76+
regionsJSONArray.put(objectOverlayJSON);
77+
78+
}
79+
80+
overlayJSON.put("labels", regionsJSONArray);
81+
82+
return overlayJSON;
83+
84+
}
85+
86+
@Override
87+
public Status process(Workspace workspace) {
88+
String objectsName = parameters.getValue(INPUT_OBJECTS, workspace);
89+
90+
Objs inputObjects = workspace.getObjects(objectsName);
91+
92+
// Getting label settings
93+
String labelMode = parameters.getValue(LABEL_MODE, workspace);
94+
int labelSize = parameters.getValue(LABEL_SIZE, workspace);
95+
int xOffset = parameters.getValue(X_OFFSET, workspace);
96+
int yOffset = parameters.getValue(Y_OFFSET, workspace);
97+
boolean centreText = parameters.getValue(CENTRE_TEXT, workspace);
98+
int decimalPlaces = parameters.getValue(DECIMAL_PLACES, workspace);
99+
boolean useScientific = parameters.getValue(USE_SCIENTIFIC, workspace);
100+
String childObjectsForLabelName = parameters.getValue(CHILD_OBJECTS_FOR_LABEL, workspace);
101+
String parentObjectsForLabelName = parameters.getValue(PARENT_OBJECT_FOR_LABEL, workspace);
102+
String partnerObjectsForLabelName = parameters.getValue(PARTNER_OBJECTS_FOR_LABEL, workspace);
103+
String measurementForLabel = parameters.getValue(MEASUREMENT_FOR_LABEL, workspace);
104+
String objectMetadataForLabel = parameters.getValue(OBJECT_METADATA_FOR_LABEL, workspace);
105+
String prefix = parameters.getValue(PREFIX, workspace);
106+
String suffix = parameters.getValue(SUFFIX, workspace);
107+
String labelPosition = parameters.getValue(LABEL_POSITION, workspace);
108+
String xPosMeas = parameters.getValue(X_POSITION_MEASUREMENT, workspace);
109+
String yPosMeas = parameters.getValue(Y_POSITION_MEASUREMENT, workspace);
110+
String zPosMeas = parameters.getValue(Z_POSITION_MEASUREMENT, workspace);
111+
int xPos = parameters.getValue(X_POSITION, workspace);
112+
int yPos = parameters.getValue(Y_POSITION, workspace);
113+
int zPos = parameters.getValue(Z_POSITION, workspace);
114+
115+
String[] measurementNames = new String[] { xPosMeas, yPosMeas, zPosMeas };
116+
int[] positions = new int[] { xPos, yPos, zPos };
117+
118+
HashMap<Integer, Color> colours = getColours(inputObjects, workspace);
119+
DecimalFormat df = LabelFactory.getDecimalFormat(decimalPlaces, useScientific);
120+
HashMap<Integer, String> labels = getLabels(inputObjects, labelMode, df, childObjectsForLabelName,
121+
parentObjectsForLabelName, partnerObjectsForLabelName, measurementForLabel, objectMetadataForLabel);
122+
appendPrefixSuffix(labels, prefix, suffix);
123+
124+
try {
125+
ProcessResult processResult = ProcessResult.getInstance();
126+
JSONObject overlayJSON = getOverlayJSON(inputObjects, labels, labelSize, colours, labelPosition, xOffset,
127+
yOffset, centreText, positions, measurementNames);
128+
129+
if (!processResult.has("overlays"))
130+
processResult.put("overlays", new JSONArray());
131+
132+
((JSONArray) processResult.get("overlays")).put(overlayJSON);
133+
134+
} catch (Exception e) {
135+
e.printStackTrace();
136+
}
137+
138+
if (showOutput)
139+
inputObjects.convertToImageIDColours().show();
140+
141+
return Status.PASS;
142+
143+
}
144+
145+
@Override
146+
public Parameters updateAndGetParameters() {
147+
Parameters returnedParameters = new Parameters();
148+
149+
returnedParameters.addAll(super.updateAndGetParameters());
150+
151+
// Returning irrelevant parameters
152+
returnedParameters.remove(INPUT_IMAGE);
153+
returnedParameters.remove(OUTPUT_SEPARATOR);
154+
returnedParameters.remove(APPLY_TO_INPUT);
155+
returnedParameters.remove(ADD_OUTPUT_TO_WORKSPACE);
156+
returnedParameters.remove(OUTPUT_IMAGE);
157+
returnedParameters.remove(EXECUTION_SEPARATOR);
158+
returnedParameters.remove(ENABLE_MULTITHREADING);
159+
160+
return returnedParameters;
161+
162+
}
163+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"colour": "#F08F90",
3+
"iconPaths": [
4+
"images/background/diatom1.png",
5+
"images/background/diatom2.png",
6+
"images/background/diatom3.png",
7+
"images/background/diatom4.png"
8+
]
9+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"text": "In development",
2+
"text": "Alpha",
33
"colour": "bg-violet-500"
44
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"text": "Alpha",
3+
"colour": "bg-violet-500"
4+
}
387 KB
Loading
9.78 KB
Binary file not shown.

0 commit comments

Comments
 (0)