Skip to content

Commit

Permalink
Merge pull request #210 from mianalysis/develop
Browse files Browse the repository at this point in the history
Updated ClassSelector colour seed
  • Loading branch information
sjcross authored Nov 28, 2024
2 parents e14a13d + 2ec54eb commit 93212f5
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public abstract class Image<T extends RealType<T> & NativeType<T>> implements Me
protected String name;
protected LinkedHashMap<String, Measurement> measurements = new LinkedHashMap<>();

public interface DisplayModes {
String COLOUR = "Colour";
String COMPOSITE = "Composite";
String COMPOSITE_INVERT = "Composite (invert)";
String COMPOSITE_MAX = "Composite (max)";
String COMPOSITE_MIN = "Composite (min)";

String[] ALL = new String[]{COLOUR, COMPOSITE, COMPOSITE_INVERT, COMPOSITE_MAX, COMPOSITE_MIN};

}

// Abstract methods

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

public abstract void setRenderer(ImageRenderer imageRenderer);

public abstract void show(String title, @Nullable LUT lut, boolean normalise, boolean composite);
public abstract void show(String title, @Nullable LUT lut, boolean normalise, String displayMode);

public abstract void show(String title, @Nullable LUT lut, boolean normalise, boolean composite,
public abstract void show(String title, @Nullable LUT lut, boolean normalise, String displayMode,
Overlay overlay);

public abstract long getWidth();
Expand Down Expand Up @@ -134,11 +145,11 @@ public Measurement getMeasurement(String name) {
}

public void show(String title, LUT lut, Overlay overlay) {
show(title, lut, true, false, overlay);
show(title, lut, true, DisplayModes.COLOUR, overlay);
}

public void show(String title, LUT lut) {
show(title, lut, true, false);
show(title, lut, true, DisplayModes.COLOUR);
}

public void show(String title) {
Expand All @@ -158,28 +169,28 @@ public void show(Overlay overlay) {
}

public void show(boolean normalise) {
show(name, null, normalise, false);
show(name, null, normalise, DisplayModes.COLOUR);
}

@Deprecated
public void showImage(String title, @Nullable LUT lut, boolean normalise, boolean composite) {
show(title, lut, normalise, composite);
public void showImage(String title, @Nullable LUT lut, boolean normalise, String displayMode) {
show(title, lut, normalise, displayMode);
}

@Deprecated
public void showImage(String title, @Nullable LUT lut, boolean normalise, boolean composite,
public void showImage(String title, @Nullable LUT lut, boolean normalise, String displayMode,
Overlay overlay) {
show(title, lut, normalise, composite, overlay);
show(title, lut, normalise, displayMode, overlay);
}

@Deprecated
public void showImage(String title, LUT lut, Overlay overlay) {
show(title, lut, true, false, overlay);
show(title, lut, true, DisplayModes.COLOUR, overlay);
}

@Deprecated
public void showImage(String title, LUT lut) {
show(title, lut, true, false);
show(title, lut, true, DisplayModes.COLOUR);
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ public void addObjectCentroid(Obj obj, float hue) {
}
}

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

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

public ImagePlusImage duplicate(String outputImageName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ public static <T extends RealType<T> & NativeType<T>> void setCalibration(ImageP
}
}

public void show(String title, @Nullable LUT lut, boolean normalise, boolean composite) {
public void show(String title, @Nullable LUT lut, boolean normalise, String displayMode) {
// Show using this overlay
show(title, lut, normalise, composite, overlay);
show(title, lut, normalise, displayMode, overlay);
}

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

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

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

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

if (composite && dispIpl.getNChannels() > 1)
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
else
dispIpl.setDisplayMode(CompositeImage.COLOR);
switch (displayMode) {
case Image.DisplayModes.COLOUR:
dispIpl.setDisplayMode(CompositeImage.COLOR);
break;

case Image.DisplayModes.COMPOSITE:
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
dispIpl.setProp("CompositeProjection", "Sum");
break;

case Image.DisplayModes.COMPOSITE_INVERT:
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
dispIpl.setProp("CompositeProjection", "Invert");
break;

case Image.DisplayModes.COMPOSITE_MAX:
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
dispIpl.setProp("CompositeProjection", "Max");
break;

case Image.DisplayModes.COMPOSITE_MIN:
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
dispIpl.setProp("CompositeProjection", "Min");
break;
}

dispIpl.repaintWindow();
dispIpl.show();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
import io.github.mianalysis.mia.object.image.Image;

public interface ImageRenderer {
public void render(Image image, String title, @Nullable LUT lut, boolean normalise, boolean composite, Overlay overlay);
public void render(Image image, String title, @Nullable LUT lut, boolean normalise, String displayMode, Overlay overlay);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,48 @@
public class ImgPlusRenderer implements ImageRenderer {

@Override
public void render(Image image, String title, LUT lut, boolean normalise, boolean composite, Overlay overlay) {
ImagePlus ipl = ImageJFunctions.show(image.getImgPlus());
public void render(Image image, String title, LUT lut, boolean normalise, String displayMode, Overlay overlay) {
ImagePlus dispIpl = ImageJFunctions.show(image.getImgPlus());

// Adds the specified overlay rather than the overlay associated with this image
// ImagePlus ipl = image.getImagePlus();
ImgPlus img = image.getImgPlus();

if (lut != null && ipl.getBitDepth() != 24)
ipl.setLut(lut);
if (lut != null && dispIpl.getBitDepth() != 24)
dispIpl.setLut(lut);

if (composite && ipl.getNChannels() > 1)
ipl.setDisplayMode(CompositeImage.COMPOSITE);
else
ipl.setDisplayMode(CompositeImage.COLOR);
switch (displayMode) {
case Image.DisplayModes.COLOUR:
dispIpl.setDisplayMode(CompositeImage.COLOR);
break;

ImgPlusImage.setCalibration(ipl, img);
ipl.setOverlay(overlay);
case Image.DisplayModes.COMPOSITE:
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
dispIpl.setProp("CompositeProjection", "Sum");
break;

ipl.setTitle(title);
case Image.DisplayModes.COMPOSITE_INVERT:
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
dispIpl.setProp("CompositeProjection", "Invert");
break;

ipl.show();
case Image.DisplayModes.COMPOSITE_MAX:
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
dispIpl.setProp("CompositeProjection", "Max");
break;

case Image.DisplayModes.COMPOSITE_MIN:
dispIpl.setDisplayMode(CompositeImage.COMPOSITE);
dispIpl.setProp("CompositeProjection", "Min");
break;
}

ImgPlusImage.setCalibration(dispIpl, img);
dispIpl.setOverlay(overlay);

dispIpl.setTitle(title);

dispIpl.show();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ public Status process(Workspace workspace) {
Image outputImage = ImageFactory.createImage(outputImageName, inputImagePlus);
workspace.addImage(outputImage);
if (showOutput)
outputImage.show(outputImageName, null, false, true);
outputImage.show(outputImageName, null, false, Image.DisplayModes.COMPOSITE);

} else {
if (showOutput)
inputImage.show(inputImageName, null, false, true);
inputImage.show(inputImageName, null, false, Image.DisplayModes.COMPOSITE);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package io.github.mianalysis.mia.module.images.configure;

import java.awt.Color;
import java.io.File;
import java.util.Arrays;
import java.util.TreeMap;
import java.util.TreeSet;

import org.apache.commons.lang.WordUtils;
import org.scijava.Priority;
import org.scijava.plugin.Plugin;

import ij.CompositeImage;
import ij.IJ;
import ij.ImagePlus;
import ij.plugin.LutLoader;
import ij.process.LUT;
import io.github.mianalysis.mia.module.Categories;
import io.github.mianalysis.mia.module.Category;
Expand All @@ -15,6 +22,7 @@
import io.github.mianalysis.mia.object.Workspace;
import io.github.mianalysis.mia.object.image.Image;
import io.github.mianalysis.mia.object.imagej.LUTs;
import io.github.mianalysis.mia.object.parameters.BooleanP;
import io.github.mianalysis.mia.object.parameters.ChoiceP;
import io.github.mianalysis.mia.object.parameters.InputImageP;
import io.github.mianalysis.mia.object.parameters.Parameters;
Expand Down Expand Up @@ -97,6 +105,12 @@ public class SetLookupTable extends Module {
*/
public static final String DISPLAY_MODE = "Display mode";

public static final String INVERT_LUT = "Invert LUT";


TreeMap<String,String> imageJLUTs;
// TreeMap<String, String> allLUTs;

public SetLookupTable(Modules modules) {
super("Set lookup table", modules);
}
Expand Down Expand Up @@ -261,6 +275,7 @@ public Status process(Workspace workspace) {
int channel = parameters.getValue(CHANNEL, workspace);
String displayMode = parameters.getValue(DISPLAY_MODE, workspace);
double wavelengthNM = parameters.getValue(WAVELENGTH, workspace);
boolean invertLUT = parameters.getValue(INVERT_LUT, workspace);

// If this image doesn't exist, skip this module. This returns true, because
// this isn't terminal for the analysis.
Expand All @@ -275,13 +290,23 @@ public Status process(Workspace workspace) {
switch (channelMode) {
case ChannelModes.ALL_CHANNELS:
case ChannelModes.SPECIFIC_CHANNELS:
LUT lut = getLUT(lookupTableName, wavelengthNM);
LUT lut;
if (imageJLUTs.keySet().contains(lookupTableName))
lut = LutLoader.openLut(IJ.getDir("luts") + lookupTableName + ".lut");
else
lut = getLUT(lookupTableName, wavelengthNM);

switch (displayMode) {
case DisplayModes.SET_ZERO_TO_BLACK:
lut = setZeroToBlack(lut);
break;
}

if (invertLUT)
lut = lut.createInvertedLut();

setLUT(inputImage, lut, channelMode, channel);

break;
case ChannelModes.COPY_FROM_IMAGE:
Image referenceImage = workspace.getImage(referenceImageName);
Expand All @@ -292,7 +317,7 @@ public Status process(Workspace workspace) {
inputImage.getImagePlus().updateChannelAndDraw();

if (showOutput)
inputImage.show(inputImageName, null, false, true);
inputImage.show(inputImageName, null, false, Image.DisplayModes.COMPOSITE);

return Status.PASS;

Expand All @@ -307,9 +332,22 @@ protected void initialiseParameters() {
parameters.add(new ChoiceP(CHANNEL_MODE, this, ChannelModes.ALL_CHANNELS, ChannelModes.ALL));
parameters.add(new InputImageP(REFERENCE_IMAGE, this));
parameters.add(new IntegerP(CHANNEL, this, 1));
parameters.add(new ChoiceP(LOOKUP_TABLE, this, LookupTables.GREY, LookupTables.ALL));

TreeSet<String> allLUTs = new TreeSet<>();
imageJLUTs = new TreeMap<>();

String[] lutFiles = new File(IJ.getDirectory("luts")).list();
if (lutFiles != null)
Arrays.stream(lutFiles).forEach(v -> imageJLUTs.put(WordUtils.capitalize(v.replace(".lut", "")),v));

allLUTs.addAll(imageJLUTs.keySet());
Arrays.stream(LookupTables.ALL).forEach(v -> allLUTs.add(v));

parameters.add(new ChoiceP(LOOKUP_TABLE, this, LookupTables.GREY,
allLUTs.toArray(new String[allLUTs.size()])));
parameters.add(new DoubleP(WAVELENGTH, this, 405));
parameters.add(new ChoiceP(DISPLAY_MODE, this, DisplayModes.FULL_RANGE, DisplayModes.ALL));
parameters.add(new BooleanP(INVERT_LUT, this, false));

addParameterDescriptions();

Expand All @@ -332,6 +370,7 @@ public Parameters updateAndGetParameters() {
if (((String) parameters.getValue(LOOKUP_TABLE, workspace)).equals(LookupTables.FROM_WAVELENGTH))
returnedParameters.add(parameters.getParameter(WAVELENGTH));
returnedParameters.add(parameters.getParameter(DISPLAY_MODE));
returnedParameters.add(parameters.getParameter(INVERT_LUT));
break;
case ChannelModes.COPY_FROM_IMAGE:
returnedParameters.add(parameters.getParameter(REFERENCE_IMAGE));
Expand All @@ -342,6 +381,7 @@ public Parameters updateAndGetParameters() {
if (((String) parameters.getValue(LOOKUP_TABLE, workspace)).equals(LookupTables.FROM_WAVELENGTH))
returnedParameters.add(parameters.getParameter(WAVELENGTH));
returnedParameters.add(parameters.getParameter(DISPLAY_MODE));
returnedParameters.add(parameters.getParameter(INVERT_LUT));
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ public Status process(Workspace workspace) {
Image outputImage = ImageFactory.createImage(outputImageName, inputImagePlus);
workspace.addImage(outputImage);
if (showOutput)
outputImage.show(outputImageName, LUT.createLutFromColor(Color.WHITE), false, true);
outputImage.show(outputImageName, LUT.createLutFromColor(Color.WHITE), false, Image.DisplayModes.COMPOSITE);

} else {
if (showOutput)
inputImage.show(inputImageName, LUT.createLutFromColor(Color.WHITE), false, true);
inputImage.show(inputImageName, LUT.createLutFromColor(Color.WHITE), false, Image.DisplayModes.COMPOSITE);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ public Status process(Workspace workspace) {
HashMap<Integer, Float> hues2 = ColourFactory.getParentIDHues(childObjects, parentObjectName, false);
Image childImage = childObjects.convertToImage(childObjectName, hues2, 32, false);
SetDisplayRange.setDisplayRangeManual(childImage, new double[] { 0, maxID });
childImage.show(childObjectName, LUTs.Random(true, false), false, false);
childImage.show(childObjectName, LUTs.Random(true, false), false, Image.DisplayModes.COLOUR);

}

Expand Down
Loading

0 comments on commit 93212f5

Please sign in to comment.