Skip to content

Commit 93212f5

Browse files
authored
Merge pull request #210 from mianalysis/develop
Updated ClassSelector colour seed
2 parents e14a13d + 2ec54eb commit 93212f5

File tree

13 files changed

+219
-113
lines changed

13 files changed

+219
-113
lines changed

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ public abstract class Image<T extends RealType<T> & NativeType<T>> implements Me
3838
protected String name;
3939
protected LinkedHashMap<String, Measurement> measurements = new LinkedHashMap<>();
4040

41+
public interface DisplayModes {
42+
String COLOUR = "Colour";
43+
String COMPOSITE = "Composite";
44+
String COMPOSITE_INVERT = "Composite (invert)";
45+
String COMPOSITE_MAX = "Composite (max)";
46+
String COMPOSITE_MIN = "Composite (min)";
47+
48+
String[] ALL = new String[]{COLOUR, COMPOSITE, COMPOSITE_INVERT, COMPOSITE_MAX, COMPOSITE_MIN};
49+
50+
}
51+
4152
// Abstract methods
4253

4354
public abstract ImageRenderer getRenderer();
@@ -46,9 +57,9 @@ public abstract class Image<T extends RealType<T> & NativeType<T>> implements Me
4657

4758
public abstract void setRenderer(ImageRenderer imageRenderer);
4859

49-
public abstract void show(String title, @Nullable LUT lut, boolean normalise, boolean composite);
60+
public abstract void show(String title, @Nullable LUT lut, boolean normalise, String displayMode);
5061

51-
public abstract void show(String title, @Nullable LUT lut, boolean normalise, boolean composite,
62+
public abstract void show(String title, @Nullable LUT lut, boolean normalise, String displayMode,
5263
Overlay overlay);
5364

5465
public abstract long getWidth();
@@ -134,11 +145,11 @@ public Measurement getMeasurement(String name) {
134145
}
135146

136147
public void show(String title, LUT lut, Overlay overlay) {
137-
show(title, lut, true, false, overlay);
148+
show(title, lut, true, DisplayModes.COLOUR, overlay);
138149
}
139150

140151
public void show(String title, LUT lut) {
141-
show(title, lut, true, false);
152+
show(title, lut, true, DisplayModes.COLOUR);
142153
}
143154

144155
public void show(String title) {
@@ -158,28 +169,28 @@ public void show(Overlay overlay) {
158169
}
159170

160171
public void show(boolean normalise) {
161-
show(name, null, normalise, false);
172+
show(name, null, normalise, DisplayModes.COLOUR);
162173
}
163174

164175
@Deprecated
165-
public void showImage(String title, @Nullable LUT lut, boolean normalise, boolean composite) {
166-
show(title, lut, normalise, composite);
176+
public void showImage(String title, @Nullable LUT lut, boolean normalise, String displayMode) {
177+
show(title, lut, normalise, displayMode);
167178
}
168179

169180
@Deprecated
170-
public void showImage(String title, @Nullable LUT lut, boolean normalise, boolean composite,
181+
public void showImage(String title, @Nullable LUT lut, boolean normalise, String displayMode,
171182
Overlay overlay) {
172-
show(title, lut, normalise, composite, overlay);
183+
show(title, lut, normalise, displayMode, overlay);
173184
}
174185

175186
@Deprecated
176187
public void showImage(String title, LUT lut, Overlay overlay) {
177-
show(title, lut, true, false, overlay);
188+
show(title, lut, true, DisplayModes.COLOUR, overlay);
178189
}
179190

180191
@Deprecated
181192
public void showImage(String title, LUT lut) {
182-
show(title, lut, true, false);
193+
show(title, lut, true, DisplayModes.COLOUR);
183194
}
184195

185196
@Deprecated

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,14 @@ public void addObjectCentroid(Obj obj, float hue) {
192192
}
193193
}
194194

195-
public void show(String title, @Nullable LUT lut, boolean normalise, boolean composite) {
195+
public void show(String title, @Nullable LUT lut, boolean normalise, String displayMode) {
196196
// Show using this overlay
197197
Overlay overlay = imagePlus.getOverlay() == null ? null : imagePlus.getOverlay().duplicate();
198-
show(title, lut, normalise, composite, overlay);
198+
show(title, lut, normalise, displayMode, overlay);
199199
}
200200

201-
public void show(String title, @Nullable LUT lut, boolean normalise, boolean composite, Overlay overlay) {
202-
getRenderer().render(this, title, lut, normalise, composite, overlay);
201+
public void show(String title, @Nullable LUT lut, boolean normalise, String displayMode, Overlay overlay) {
202+
getRenderer().render(this, title, lut, normalise, displayMode, overlay);
203203
}
204204

205205
public ImagePlusImage duplicate(String outputImageName) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ public static <T extends RealType<T> & NativeType<T>> void setCalibration(ImageP
257257
}
258258
}
259259

260-
public void show(String title, @Nullable LUT lut, boolean normalise, boolean composite) {
260+
public void show(String title, @Nullable LUT lut, boolean normalise, String displayMode) {
261261
// Show using this overlay
262-
show(title, lut, normalise, composite, overlay);
262+
show(title, lut, normalise, displayMode, overlay);
263263
}
264264

265-
public void show(String title, @Nullable LUT lut, boolean normalise, boolean composite, Overlay overlay) {
266-
getRenderer().render(this, title, lut, normalise, composite, overlay);
265+
public void show(String title, @Nullable LUT lut, boolean normalise, String displayMode, Overlay overlay) {
266+
getRenderer().render(this, title, lut, normalise, displayMode, overlay);
267267

268268
}
269269

mia-core/src/main/java/io/github/mianalysis/mia/object/image/renderer/ImagePlusRenderer.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
public class ImagePlusRenderer implements ImageRenderer {
1414
@Override
15-
public void render(Image image, String title, @Nullable LUT lut, boolean normalise, boolean composite, Overlay overlay) {
15+
public void render(Image image, String title, @Nullable LUT lut, boolean normalise, String displayMode,
16+
Overlay overlay) {
1617
ImagePlus imagePlus = image.getImagePlus();
1718

1819
// Adds the specified overlay rather than the overlay associated with this image
@@ -27,13 +28,34 @@ public void render(Image image, String title, @Nullable LUT lut, boolean normali
2728
if (lut != null && dispIpl.getBitDepth() != 24)
2829
dispIpl.setLut(lut);
2930

30-
if (composite && dispIpl.getNChannels() > 1)
31-
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
32-
else
33-
dispIpl.setDisplayMode(CompositeImage.COLOR);
31+
switch (displayMode) {
32+
case Image.DisplayModes.COLOUR:
33+
dispIpl.setDisplayMode(CompositeImage.COLOR);
34+
break;
35+
36+
case Image.DisplayModes.COMPOSITE:
37+
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
38+
dispIpl.setProp("CompositeProjection", "Sum");
39+
break;
40+
41+
case Image.DisplayModes.COMPOSITE_INVERT:
42+
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
43+
dispIpl.setProp("CompositeProjection", "Invert");
44+
break;
45+
46+
case Image.DisplayModes.COMPOSITE_MAX:
47+
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
48+
dispIpl.setProp("CompositeProjection", "Max");
49+
break;
50+
51+
case Image.DisplayModes.COMPOSITE_MIN:
52+
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
53+
dispIpl.setProp("CompositeProjection", "Min");
54+
break;
55+
}
3456

3557
dispIpl.repaintWindow();
3658
dispIpl.show();
37-
38-
}
59+
60+
}
3961
}

mia-core/src/main/java/io/github/mianalysis/mia/object/image/renderer/ImageRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
import io.github.mianalysis.mia.object.image.Image;
88

99
public interface ImageRenderer {
10-
public void render(Image image, String title, @Nullable LUT lut, boolean normalise, boolean composite, Overlay overlay);
10+
public void render(Image image, String title, @Nullable LUT lut, boolean normalise, String displayMode, Overlay overlay);
1111
}

mia-core/src/main/java/io/github/mianalysis/mia/object/image/renderer/ImgPlusRenderer.java

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,48 @@
1212
public class ImgPlusRenderer implements ImageRenderer {
1313

1414
@Override
15-
public void render(Image image, String title, LUT lut, boolean normalise, boolean composite, Overlay overlay) {
16-
ImagePlus ipl = ImageJFunctions.show(image.getImgPlus());
15+
public void render(Image image, String title, LUT lut, boolean normalise, String displayMode, Overlay overlay) {
16+
ImagePlus dispIpl = ImageJFunctions.show(image.getImgPlus());
17+
1718
// Adds the specified overlay rather than the overlay associated with this image
1819
// ImagePlus ipl = image.getImagePlus();
1920
ImgPlus img = image.getImgPlus();
2021

21-
if (lut != null && ipl.getBitDepth() != 24)
22-
ipl.setLut(lut);
22+
if (lut != null && dispIpl.getBitDepth() != 24)
23+
dispIpl.setLut(lut);
2324

24-
if (composite && ipl.getNChannels() > 1)
25-
ipl.setDisplayMode(CompositeImage.COMPOSITE);
26-
else
27-
ipl.setDisplayMode(CompositeImage.COLOR);
25+
switch (displayMode) {
26+
case Image.DisplayModes.COLOUR:
27+
dispIpl.setDisplayMode(CompositeImage.COLOR);
28+
break;
2829

29-
ImgPlusImage.setCalibration(ipl, img);
30-
ipl.setOverlay(overlay);
30+
case Image.DisplayModes.COMPOSITE:
31+
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
32+
dispIpl.setProp("CompositeProjection", "Sum");
33+
break;
3134

32-
ipl.setTitle(title);
35+
case Image.DisplayModes.COMPOSITE_INVERT:
36+
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
37+
dispIpl.setProp("CompositeProjection", "Invert");
38+
break;
3339

34-
ipl.show();
40+
case Image.DisplayModes.COMPOSITE_MAX:
41+
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
42+
dispIpl.setProp("CompositeProjection", "Max");
43+
break;
44+
45+
case Image.DisplayModes.COMPOSITE_MIN:
46+
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
47+
dispIpl.setProp("CompositeProjection", "Min");
48+
break;
49+
}
50+
51+
ImgPlusImage.setCalibration(dispIpl, img);
52+
dispIpl.setOverlay(overlay);
53+
54+
dispIpl.setTitle(title);
55+
56+
dispIpl.show();
3557

3658
}
3759
}

mia-modules/src/main/java/io/github/mianalysis/mia/module/images/configure/SetDisplayRange.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,11 @@ public Status process(Workspace workspace) {
304304
Image outputImage = ImageFactory.createImage(outputImageName, inputImagePlus);
305305
workspace.addImage(outputImage);
306306
if (showOutput)
307-
outputImage.show(outputImageName, null, false, true);
307+
outputImage.show(outputImageName, null, false, Image.DisplayModes.COMPOSITE);
308308

309309
} else {
310310
if (showOutput)
311-
inputImage.show(inputImageName, null, false, true);
311+
inputImage.show(inputImageName, null, false, Image.DisplayModes.COMPOSITE);
312312

313313
}
314314

mia-modules/src/main/java/io/github/mianalysis/mia/module/images/configure/SetLookupTable.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package io.github.mianalysis.mia.module.images.configure;
22

33
import java.awt.Color;
4+
import java.io.File;
5+
import java.util.Arrays;
6+
import java.util.TreeMap;
7+
import java.util.TreeSet;
48

9+
import org.apache.commons.lang.WordUtils;
510
import org.scijava.Priority;
611
import org.scijava.plugin.Plugin;
712

813
import ij.CompositeImage;
14+
import ij.IJ;
915
import ij.ImagePlus;
16+
import ij.plugin.LutLoader;
1017
import ij.process.LUT;
1118
import io.github.mianalysis.mia.module.Categories;
1219
import io.github.mianalysis.mia.module.Category;
@@ -15,6 +22,7 @@
1522
import io.github.mianalysis.mia.object.Workspace;
1623
import io.github.mianalysis.mia.object.image.Image;
1724
import io.github.mianalysis.mia.object.imagej.LUTs;
25+
import io.github.mianalysis.mia.object.parameters.BooleanP;
1826
import io.github.mianalysis.mia.object.parameters.ChoiceP;
1927
import io.github.mianalysis.mia.object.parameters.InputImageP;
2028
import io.github.mianalysis.mia.object.parameters.Parameters;
@@ -97,6 +105,12 @@ public class SetLookupTable extends Module {
97105
*/
98106
public static final String DISPLAY_MODE = "Display mode";
99107

108+
public static final String INVERT_LUT = "Invert LUT";
109+
110+
111+
TreeMap<String,String> imageJLUTs;
112+
// TreeMap<String, String> allLUTs;
113+
100114
public SetLookupTable(Modules modules) {
101115
super("Set lookup table", modules);
102116
}
@@ -261,6 +275,7 @@ public Status process(Workspace workspace) {
261275
int channel = parameters.getValue(CHANNEL, workspace);
262276
String displayMode = parameters.getValue(DISPLAY_MODE, workspace);
263277
double wavelengthNM = parameters.getValue(WAVELENGTH, workspace);
278+
boolean invertLUT = parameters.getValue(INVERT_LUT, workspace);
264279

265280
// If this image doesn't exist, skip this module. This returns true, because
266281
// this isn't terminal for the analysis.
@@ -275,13 +290,23 @@ public Status process(Workspace workspace) {
275290
switch (channelMode) {
276291
case ChannelModes.ALL_CHANNELS:
277292
case ChannelModes.SPECIFIC_CHANNELS:
278-
LUT lut = getLUT(lookupTableName, wavelengthNM);
293+
LUT lut;
294+
if (imageJLUTs.keySet().contains(lookupTableName))
295+
lut = LutLoader.openLut(IJ.getDir("luts") + lookupTableName + ".lut");
296+
else
297+
lut = getLUT(lookupTableName, wavelengthNM);
298+
279299
switch (displayMode) {
280300
case DisplayModes.SET_ZERO_TO_BLACK:
281301
lut = setZeroToBlack(lut);
282302
break;
283303
}
304+
305+
if (invertLUT)
306+
lut = lut.createInvertedLut();
307+
284308
setLUT(inputImage, lut, channelMode, channel);
309+
285310
break;
286311
case ChannelModes.COPY_FROM_IMAGE:
287312
Image referenceImage = workspace.getImage(referenceImageName);
@@ -292,7 +317,7 @@ public Status process(Workspace workspace) {
292317
inputImage.getImagePlus().updateChannelAndDraw();
293318

294319
if (showOutput)
295-
inputImage.show(inputImageName, null, false, true);
320+
inputImage.show(inputImageName, null, false, Image.DisplayModes.COMPOSITE);
296321

297322
return Status.PASS;
298323

@@ -307,9 +332,22 @@ protected void initialiseParameters() {
307332
parameters.add(new ChoiceP(CHANNEL_MODE, this, ChannelModes.ALL_CHANNELS, ChannelModes.ALL));
308333
parameters.add(new InputImageP(REFERENCE_IMAGE, this));
309334
parameters.add(new IntegerP(CHANNEL, this, 1));
310-
parameters.add(new ChoiceP(LOOKUP_TABLE, this, LookupTables.GREY, LookupTables.ALL));
335+
336+
TreeSet<String> allLUTs = new TreeSet<>();
337+
imageJLUTs = new TreeMap<>();
338+
339+
String[] lutFiles = new File(IJ.getDirectory("luts")).list();
340+
if (lutFiles != null)
341+
Arrays.stream(lutFiles).forEach(v -> imageJLUTs.put(WordUtils.capitalize(v.replace(".lut", "")),v));
342+
343+
allLUTs.addAll(imageJLUTs.keySet());
344+
Arrays.stream(LookupTables.ALL).forEach(v -> allLUTs.add(v));
345+
346+
parameters.add(new ChoiceP(LOOKUP_TABLE, this, LookupTables.GREY,
347+
allLUTs.toArray(new String[allLUTs.size()])));
311348
parameters.add(new DoubleP(WAVELENGTH, this, 405));
312349
parameters.add(new ChoiceP(DISPLAY_MODE, this, DisplayModes.FULL_RANGE, DisplayModes.ALL));
350+
parameters.add(new BooleanP(INVERT_LUT, this, false));
313351

314352
addParameterDescriptions();
315353

@@ -332,6 +370,7 @@ public Parameters updateAndGetParameters() {
332370
if (((String) parameters.getValue(LOOKUP_TABLE, workspace)).equals(LookupTables.FROM_WAVELENGTH))
333371
returnedParameters.add(parameters.getParameter(WAVELENGTH));
334372
returnedParameters.add(parameters.getParameter(DISPLAY_MODE));
373+
returnedParameters.add(parameters.getParameter(INVERT_LUT));
335374
break;
336375
case ChannelModes.COPY_FROM_IMAGE:
337376
returnedParameters.add(parameters.getParameter(REFERENCE_IMAGE));
@@ -342,6 +381,7 @@ public Parameters updateAndGetParameters() {
342381
if (((String) parameters.getValue(LOOKUP_TABLE, workspace)).equals(LookupTables.FROM_WAVELENGTH))
343382
returnedParameters.add(parameters.getParameter(WAVELENGTH));
344383
returnedParameters.add(parameters.getParameter(DISPLAY_MODE));
384+
returnedParameters.add(parameters.getParameter(INVERT_LUT));
345385
break;
346386
}
347387

mia-modules/src/main/java/io/github/mianalysis/mia/module/images/process/NormaliseIntensity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ public Status process(Workspace workspace) {
328328
Image outputImage = ImageFactory.createImage(outputImageName, inputImagePlus);
329329
workspace.addImage(outputImage);
330330
if (showOutput)
331-
outputImage.show(outputImageName, LUT.createLutFromColor(Color.WHITE), false, true);
331+
outputImage.show(outputImageName, LUT.createLutFromColor(Color.WHITE), false, Image.DisplayModes.COMPOSITE);
332332

333333
} else {
334334
if (showOutput)
335-
inputImage.show(inputImageName, LUT.createLutFromColor(Color.WHITE), false, true);
335+
inputImage.show(inputImageName, LUT.createLutFromColor(Color.WHITE), false, Image.DisplayModes.COMPOSITE);
336336

337337
}
338338

mia-modules/src/main/java/io/github/mianalysis/mia/module/objects/relate/RelateManyToOne.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ public Status process(Workspace workspace) {
744744
HashMap<Integer, Float> hues2 = ColourFactory.getParentIDHues(childObjects, parentObjectName, false);
745745
Image childImage = childObjects.convertToImage(childObjectName, hues2, 32, false);
746746
SetDisplayRange.setDisplayRangeManual(childImage, new double[] { 0, maxID });
747-
childImage.show(childObjectName, LUTs.Random(true, false), false, false);
747+
childImage.show(childObjectName, LUTs.Random(true, false), false, Image.DisplayModes.COLOUR);
748748

749749
}
750750

0 commit comments

Comments
 (0)