use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class DensityImage method computeRipleysPlot.
/**
* Compute the Ripley's L-function for user selected radii and show it on a plot.
*
* @param results
*/
private void computeRipleysPlot(MemoryPeakResults results) {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Compute Ripley's L(r) - r plot");
gd.addNumericField("Min_radius", minR, 2);
gd.addNumericField("Max_radius", maxR, 2);
gd.addNumericField("Increment", incrementR, 2);
gd.addCheckbox("Confidence_intervals", confidenceIntervals);
gd.showDialog();
if (gd.wasCanceled())
return;
minR = gd.getNextNumber();
maxR = gd.getNextNumber();
incrementR = gd.getNextNumber();
confidenceIntervals = gd.getNextBoolean();
if (minR > maxR || incrementR < 0 || gd.invalidNumber()) {
IJ.error(TITLE, "Invalid radius parameters");
return;
}
DensityManager dm = createDensityManager(results);
double[][] values = calculateLScores(dm);
// 99% confidence intervals
final int iterations = (confidenceIntervals) ? 99 : 0;
double[] upper = null;
double[] lower = null;
Rectangle bounds = results.getBounds();
// Use a uniform distribution for the coordinates
HaltonSequenceGenerator dist = new HaltonSequenceGenerator(2);
dist.skipTo(new Well19937c(System.currentTimeMillis() + System.identityHashCode(this)).nextInt());
for (int i = 0; i < iterations; i++) {
IJ.showProgress(i, iterations);
IJ.showStatus(String.format("L-score confidence interval %d / %d", i + 1, iterations));
// Randomise coordinates
float[] x = new float[results.size()];
float[] y = new float[x.length];
for (int j = x.length; j-- > 0; ) {
final double[] d = dist.nextVector();
x[j] = (float) (d[0] * bounds.width);
y[j] = (float) (d[1] * bounds.height);
}
double[][] values2 = calculateLScores(new DensityManager(x, y, bounds));
if (upper == null) {
upper = values2[1];
lower = new double[upper.length];
System.arraycopy(upper, 0, lower, 0, upper.length);
} else {
for (int m = upper.length; m-- > 0; ) {
if (upper[m] < values2[1][m])
upper[m] = values2[1][m];
if (lower[m] > values2[1][m])
lower[m] = values2[1][m];
}
}
}
String title = results.getName() + " Ripley's (L(r) - r) / r";
Plot2 plot = new Plot2(title, "Radius", "(L(r) - r) / r", values[0], values[1]);
// Get the limits
double yMin = min(0, values[1]);
double yMax = max(0, values[1]);
if (iterations > 0) {
yMin = min(yMin, lower);
yMax = max(yMax, upper);
}
plot.setLimits(0, values[0][values[0].length - 1], yMin, yMax);
if (iterations > 0) {
plot.setColor(Color.BLUE);
plot.addPoints(values[0], upper, 1);
plot.setColor(Color.RED);
plot.addPoints(values[0], lower, 1);
plot.setColor(Color.BLACK);
}
Utils.display(title, plot);
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class CropResults method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "There are no fitting results in memory");
return;
}
// Show a dialog allowing the results set to be filtered
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Select a dataset to crop");
ResultsManager.addInput(gd, inputOption, InputSource.MEMORY);
gd.showDialog();
if (gd.wasCanceled())
return;
inputOption = ResultsManager.getInputSource(gd);
results = ResultsManager.loadInputResults(inputOption, false);
if (results == null || results.size() == 0) {
IJ.error(TITLE, "No results could be loaded");
IJ.showStatus("");
return;
}
if (!showDialog())
return;
cropResults();
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class DrawClusters method showDialog.
private boolean showDialog() {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
ArrayList<String> titles = new ArrayList<String>(WindowManager.getImageCount());
titles.add("[None]");
int[] idList = WindowManager.getIDList();
if (idList != null)
for (int id : idList) {
ImagePlus imp = WindowManager.getImage(id);
if (imp != null)
titles.add(imp.getTitle());
}
gd.addMessage("Draw the clusters on an image");
ResultsManager.addInput(gd, "Input", inputOption, InputSource.MEMORY_CLUSTERED);
gd.addChoice("Image", titles.toArray(new String[0]), title);
gd.addNumericField("Image_size", imageSize, 0);
gd.addCheckbox("Expand_to_singles", expandToSingles);
gd.addSlider("Min_size", 1, 15, minSize);
gd.addSlider("Max_size", 0, 20, maxSize);
gd.addCheckbox("Traces (draw lines)", drawLines);
gd.addChoice("Sort", sorts, sorts[sort]);
gd.addCheckbox("Spline_fit (traces only)", splineFit);
gd.addCheckbox("Use_stack_position", useStackPosition);
gd.addChoice("LUT", LUTHelper.luts, LUTHelper.luts[lut]);
gd.showDialog();
if (gd.wasCanceled())
return false;
inputOption = ResultsManager.getInputSource(gd);
title = gd.getNextChoice();
imageSize = (int) Math.abs(gd.getNextNumber());
expandToSingles = gd.getNextBoolean();
minSize = (int) Math.abs(gd.getNextNumber());
maxSize = (int) Math.abs(gd.getNextNumber());
drawLines = gd.getNextBoolean();
sort = gd.getNextChoiceIndex();
splineFit = gd.getNextBoolean();
useStackPosition = gd.getNextBoolean();
lut = gd.getNextChoiceIndex();
return true;
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class DriftCalculator method showStackDialog.
private ImageStack showStackDialog(String[] stackTitles) {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
gd.addMessage("Compute the drift using a reference stack alignment");
gd.addChoice("Stack_image", stackTitles, stackTitle);
gd.addMessage("Frame = previous + spacing");
gd.addNumericField("Start_frame", startFrame, 0);
gd.addSlider("Frame_spacing", 1, 20, frameSpacing);
String[] methods = ImageProcessor.getInterpolationMethods();
gd.addChoice("Interpolation_method", methods, methods[interpolationMethod]);
methods = new String[] { AlignImagesFFT.SubPixelMethod.CUBIC.toString(), AlignImagesFFT.SubPixelMethod.GAUSSIAN.toString() };
gd.addChoice("Sub-pixel_method", methods, subPixelMethod.toString());
gd.showDialog();
if (gd.wasCanceled())
return null;
stackTitle = gd.getNextChoice();
startFrame = (int) gd.getNextNumber();
frameSpacing = (int) gd.getNextNumber();
interpolationMethod = gd.getNextChoiceIndex();
subPixelMethod = (gd.getNextChoiceIndex() == 0) ? AlignImagesFFT.SubPixelMethod.CUBIC : AlignImagesFFT.SubPixelMethod.GAUSSIAN;
try {
Parameters.isAboveZero("Start frame", startFrame);
Parameters.isAboveZero("Frame spacing", frameSpacing);
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return null;
}
ImagePlus imp = WindowManager.getImage(stackTitle);
if (imp != null && imp.getStackSize() > 1)
return imp.getImageStack();
return null;
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class DriftCalculator method showDialog.
private boolean showDialog(Roi[] rois, String[] stackTitles) {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
gd.addMessage("Correct the drift in localisation results");
ResultsManager.addInput(gd, inputOption, InputSource.MEMORY);
ArrayList<String> methods = new ArrayList<String>(4);
methods.add(SUB_IMAGE_ALIGNMENT);
methods.add(DRIFT_FILE);
if (rois != null)
methods.add(MARKED_ROIS);
if (stackTitles != null)
methods.add(STACK_ALIGNMENT);
String[] items = methods.toArray(new String[methods.size()]);
gd.addChoice("Method", items, method);
gd.addMessage("Stopping criteria");
gd.addSlider("Max_iterations", 0, 100, maxIterations);
gd.addNumericField("Relative_error", relativeError, 3);
gd.addMessage("LOESS smoothing parameters");
gd.addSlider("Smoothing", 0.001, 1, smoothing);
gd.addCheckbox("Limit_smoothing", limitSmoothing);
gd.addSlider("Min_smoothing_points", 5, 50, minSmoothingPoints);
gd.addSlider("Max_smoothing_points", 5, 50, maxSmoothingPoints);
gd.addSlider("Smoothing_iterations", 1, 10, iterations);
gd.addCheckbox("Plot_drift", plotDrift);
gd.showDialog();
if (gd.wasCanceled())
return false;
inputOption = ResultsManager.getInputSource(gd);
method = gd.getNextChoice();
maxIterations = (int) gd.getNextNumber();
relativeError = gd.getNextNumber();
smoothing = gd.getNextNumber();
limitSmoothing = gd.getNextBoolean();
minSmoothingPoints = (int) gd.getNextNumber();
maxSmoothingPoints = (int) gd.getNextNumber();
iterations = (int) gd.getNextNumber();
plotDrift = gd.getNextBoolean();
// Check arguments
try {
Parameters.isPositive("Max iterations", maxIterations);
Parameters.isAboveZero("Relative error", relativeError);
Parameters.isPositive("Smoothing", smoothing);
if (limitSmoothing) {
Parameters.isEqualOrAbove("Min smoothing points", minSmoothingPoints, 3);
Parameters.isEqualOrAbove("Max smoothing points", maxSmoothingPoints, 3);
Parameters.isEqualOrAbove("Max smoothing points", maxSmoothingPoints, minSmoothingPoints);
}
Parameters.isEqualOrBelow("Smoothing", smoothing, 1);
Parameters.isPositive("Smoothing iterations", iterations);
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return false;
}
return true;
}
Aggregations