use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class BenchmarkSpotFilter method showDialog.
private boolean showDialog() {
GenericDialog gd = new GenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
StringBuilder sb = new StringBuilder();
sb.append("Finds spots in the benchmark image created by CreateData plugin.\n");
final double sa = getSa() / simulationParameters.a;
sb.append("PSF width = ").append(Utils.rounded(simulationParameters.s / simulationParameters.a)).append(" px (sa = ").append(Utils.rounded(sa)).append(" px). HWHM = ").append(Utils.rounded(sa * Gaussian2DFunction.SD_TO_HWHM_FACTOR)).append(" px\n");
sb.append("Simulation depth = ").append(Utils.rounded(simulationParameters.depth)).append(" nm");
if (simulationParameters.fixedDepth)
sb.append(" (fixed)");
sb.append("\n \nConfigure the spot filter:");
gd.addMessage(sb.toString());
if (batchMode) {
// Support enumeration of single spot filters
gd.addCheckbox("Mean", batchMean);
gd.addCheckbox("Gaussian", batchGaussian);
gd.addCheckbox("Circular", batchCircular);
gd.addCheckbox("Median", batchMedian);
gd.addSlider("Min_search_width", 1, 4, minSearch);
gd.addSlider("Max_search_width", 1, 4, maxSearch);
gd.addCheckbox("Filter_relative_distances (to HWHM)", filterRelativeDistances);
} else {
String[] filterTypes = SettingsManager.getNames((Object[]) DataFilterType.values());
gd.addChoice("Spot_filter_type", filterTypes, filterTypes[config.getDataFilterType().ordinal()]);
String[] filterNames = SettingsManager.getNames((Object[]) DataFilter.values());
gd.addChoice("Spot_filter", filterNames, filterNames[config.getDataFilter(0).ordinal()]);
gd.addCheckbox("Filter_relative_distances (to HWHM)", filterRelativeDistances);
gd.addSlider("Smoothing", 0, 2.5, config.getSmooth(0));
gd.addSlider("Search_width", 1, 4, search);
}
gd.addSlider("Border", 0, 5, border);
gd.addCheckbox("Hard_border", hardBorder);
gd.addMessage("Scoring options:");
gd.addCheckbox("Score_relative_distances (to HWHM)", scoreRelativeDistances);
gd.addSlider("Analysis_border", 0, 5, sAnalysisBorder);
gd.addChoice("Matching_method", MATCHING_METHOD, MATCHING_METHOD[matchingMethod]);
gd.addSlider("Match_distance", 0.5, 3.5, upperDistance);
gd.addSlider("Lower_distance", 0, 3.5, lowerDistance);
gd.addSlider("Signal_factor", 0, 3.5, upperSignalFactor);
gd.addSlider("Lower_factor", 0, 3.5, lowerSignalFactor);
gd.addSlider("Recall_fraction", 50, 100, recallFraction);
if (!batchMode) {
gd.addCheckbox("Show_plots", showPlot);
gd.addCheckbox("Plot_rank_by_intensity", rankByIntensity);
gd.addCheckbox("Show_failures_plots", showFailuresPlot);
gd.addCheckbox("Show_TP", showTP);
gd.addCheckbox("Show_FP", showFP);
gd.addCheckbox("Show_FN", showFN);
}
if (extraOptions)
gd.addCheckbox("Debug", sDebug);
gd.showDialog();
if (gd.wasCanceled())
return false;
fitConfig.setInitialPeakStdDev(Maths.round(sa));
if (batchMode) {
batchMean = gd.getNextBoolean();
batchGaussian = gd.getNextBoolean();
batchCircular = gd.getNextBoolean();
batchMedian = gd.getNextBoolean();
if (!(batchMean || batchGaussian || batchCircular || batchMedian))
return false;
minSearch = gd.getNextNumber();
maxSearch = gd.getNextNumber();
filterRelativeDistances = gd.getNextBoolean();
} else {
config.setDataFilterType(gd.getNextChoiceIndex());
config.setDataFilter(gd.getNextChoiceIndex(), Maths.round(Math.abs(gd.getNextNumber()), 0.001), 0);
filterRelativeDistances = gd.getNextBoolean();
search = gd.getNextNumber();
}
border = gd.getNextNumber();
hardBorder = gd.getNextBoolean();
scoreRelativeDistances = gd.getNextBoolean();
sAnalysisBorder = Math.abs(gd.getNextNumber());
matchingMethod = gd.getNextChoiceIndex();
upperDistance = Math.abs(gd.getNextNumber());
lowerDistance = Math.abs(gd.getNextNumber());
upperSignalFactor = Math.abs(gd.getNextNumber());
lowerSignalFactor = Math.abs(gd.getNextNumber());
recallFraction = Math.abs(gd.getNextNumber());
if (!batchMode) {
showPlot = gd.getNextBoolean();
rankByIntensity = gd.getNextBoolean();
showFailuresPlot = gd.getNextBoolean();
showTP = gd.getNextBoolean();
showFP = gd.getNextBoolean();
showFN = gd.getNextBoolean();
}
if (extraOptions)
debug = sDebug = gd.getNextBoolean();
if (gd.invalidNumber())
return false;
if (lowerDistance > upperDistance)
lowerDistance = upperDistance;
if (lowerSignalFactor > upperSignalFactor)
lowerSignalFactor = upperSignalFactor;
if (batchMode) {
// Clear the cached results if the setting changed
Settings settings = new Settings(simulationParameters.id, filterRelativeDistances, //search, maxSearch, // Ignore search distance for smart caching
border, scoreRelativeDistances, sAnalysisBorder, hardBorder, matchingMethod, upperDistance, lowerDistance, upperSignalFactor, lowerSignalFactor, recallFraction);
if (!settings.equals(batchSettings)) {
cachedBatchResults.clear();
}
batchSettings = settings;
// relative (if requested) so that the results are consistent with single-filter mode.
if (filterRelativeDistances) {
final double hwhmMax = config.getHWHMMax();
config.setBorder(Maths.round(border * hwhmMax, 0.001));
} else {
config.setBorder(Maths.round(border, 0.001));
}
} else {
config.setSearch(Maths.round(search, 0.001));
config.setBorder(Maths.round(border, 0.001));
// Single filter ...
// Allow more complicated filters to be configured
GlobalSettings settings = new GlobalSettings();
settings.setFitEngineConfiguration(config);
if (!PeakFit.configureDataFilter(settings, null, false))
return false;
}
int analysisBorder;
if (scoreRelativeDistances) {
// Convert distance to PSF standard deviation units
final double hwhmMax = config.getHWHMMax();
matchDistance = upperDistance * hwhmMax;
lowerMatchDistance = lowerDistance * hwhmMax;
analysisBorder = (int) (sAnalysisBorder * hwhmMax);
} else {
matchDistance = upperDistance;
lowerMatchDistance = lowerDistance;
analysisBorder = (int) (sAnalysisBorder);
}
if (analysisBorder > 0) {
lastAnalysisBorder = new Rectangle(analysisBorder, analysisBorder, imp.getWidth() - 2 * analysisBorder, imp.getHeight() - 2 * analysisBorder);
} else {
lastAnalysisBorder = new Rectangle(imp.getWidth(), imp.getHeight());
}
return true;
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class BenchmarkSpotFilter method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
extraOptions = Utils.isExtraOptions();
batchMode = "batch".equals(arg);
simulationParameters = CreateData.simulationParameters;
if (simulationParameters == null) {
IJ.error(TITLE, "No benchmark spot parameters in memory");
return;
}
imp = CreateData.getImage();
if (imp == null) {
IJ.error(TITLE, "No benchmark image");
return;
}
results = CreateData.getResults();
if (results == null) {
IJ.error(TITLE, "No benchmark results in memory");
return;
}
if (!showDialog())
return;
// Clear old results to free memory
if (filterResult != null) {
filterResult.filterResults.clear();
filterResult.filterResults = null;
filterResult = null;
}
// For graphs
windowOrganiser = new WindowOrganiser();
if (batchMode) {
// Batch mode to test enumeration of filters
final double sd = simulationParameters.s / simulationParameters.a;
final int limit = (int) Math.floor(3 * sd);
double[] searchParam = getRange(minSearch, maxSearch, 1);
// Continuous parameters
double[] pEmpty = new double[0];
double[] mParam = (batchMean) ? getRange(limit, 0.05) : pEmpty;
double[] gParam = (batchGaussian) ? getRange(limit, 0.05) : pEmpty;
// Less continuous parameters
double[] cParam = (batchCircular) ? getRange(limit, 0.5) : pEmpty;
// Discrete parameters
double[] medParam = (batchMedian) ? getRange(limit, 1) : pEmpty;
setupProgress(imp.getImageStackSize() * searchParam.length * (mParam.length + gParam.length + cParam.length + medParam.length), "Frame");
ArrayList<BatchResult[]> batchResults = new ArrayList<BatchResult[]>(cachedBatchResults.size());
config.setDataFilterType(DataFilterType.SINGLE);
for (double search : searchParam) {
// Run all, store the results for plotting.
// Allow re-use of these if they are cached to allow quick reanalysis of results.
config.setSearch(search);
if (batchMean)
batchResults.add(addToCache(DataFilter.MEAN, mParam, search));
if (batchGaussian)
batchResults.add(addToCache(DataFilter.GAUSSIAN, gParam, search));
if (batchCircular)
batchResults.add(addToCache(DataFilter.CIRCULAR_MEAN, cParam, search));
if (batchMean)
batchResults.add(addToCache(DataFilter.MEDIAN, medParam, search));
}
IJ.showProgress(-1);
IJ.showStatus("");
if (Utils.isInterrupted())
return;
// Analysis options
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("Choose performance plots:");
for (int i = 0; i < batchPlot.length; i++) gd.addCheckbox(batchPlotNames[i], batchPlot[i]);
gd.addChoice("Selection", SELECTION, SELECTION[selection]);
gd.addCheckbox("Show_plots", showPlot);
gd.addCheckbox("Plot_rank_by_intensity", rankByIntensity);
gd.addCheckbox("Show_failures_plots", showFailuresPlot);
gd.addCheckbox("Show_TP", showTP);
gd.addCheckbox("Show_FP", showFP);
gd.addCheckbox("Show_FN", showFN);
gd.showDialog();
if (gd.wasCanceled())
return;
for (int i = 0; i < batchPlot.length; i++) batchPlot[i] = gd.getNextBoolean();
selection = gd.getNextChoiceIndex();
showPlot = gd.getNextBoolean();
rankByIntensity = gd.getNextBoolean();
showFailuresPlot = gd.getNextBoolean();
showTP = gd.getNextBoolean();
showFP = gd.getNextBoolean();
showFN = gd.getNextBoolean();
// Plot charts
for (int i = 0; i < batchPlot.length; i++) plot(i, batchResults);
// Store in global singleton
filterResult = analyse(batchResults);
} else {
// Single filter mode
setupProgress(imp.getImageStackSize(), "Frame");
filterResult = run(config, filterRelativeDistances);
}
IJ.showProgress(-1);
IJ.showStatus("");
getTable(false).flush();
if (filterResult == null)
return;
// Store a clone of the config
filterResult.config = filterResult.config.clone();
// Debugging the matches
if (debug)
addSpotsToMemory(filterResult.filterResults);
if (showFailuresPlot)
showFailuresPlot(filterResult);
if (showPlot)
showPlot(filterResult);
if (isShowOverlay())
showOverlay(imp, filterResult);
windowOrganiser.tile();
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class PCPALMClusters method showDialog.
private boolean showDialog() {
if (PCPALMMolecules.molecules == null || PCPALMMolecules.molecules.size() < 2) {
Utils.log(TITLE + " defaulting to File mode");
fileInput = true;
// Ensure this gets recorded
Recorder.recordOption("Method", "File");
} else {
GenericDialog gd = new GenericDialog(TITLE);
String[] items = { "Clustering", "File" };
gd.addMessage("Fit a Binomial distribution to a histogram of cluster sizes.\n \nSelect the method to generate the histogram:");
gd.addChoice("Method", items, items[runMode]);
gd.showDialog();
if (gd.wasCanceled())
return false;
runMode = gd.getNextChoiceIndex();
fileInput = (runMode == 1);
}
if (fileInput) {
if ((histogramFile = Utils.getFilename("Histogram_file", histogramFile)) == null)
return false;
}
GenericDialog gd = new GenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
// Check if the molecules have weights
boolean haveWeights = false;
if (!fileInput) {
haveWeights = checkForWeights();
gd.addMessage("Find clusters using centroid-linkage clustering.");
gd.addNumericField("Distance (nm)", distance, 0);
String[] names = SettingsManager.getNames((Object[]) ClusteringAlgorithm.values());
gd.addChoice("Algorithm", names, names[sClusteringAlgorithm.ordinal()]);
gd.addCheckbox("Multi_thread", multiThread);
if (haveWeights)
gd.addCheckbox("Weighted_clustering", sWeightedClustering);
}
gd.addSlider("Min_N", 1, 10, minN);
gd.addSlider("Max_N", 0, 10, maxN);
gd.addCheckbox("Show_cumulative_histogram", showCumulativeHistogram);
gd.addCheckbox("Maximum_likelihood", maximumLikelihood);
if (!fileInput) {
gd.addCheckbox("Save_histogram", saveHistogram);
gd.addMessage("Histogram calibration (optional)");
gd.addCheckbox("Calibrate_histogram", calibrateHistogram);
gd.addNumericField("Frames", frames, 0);
gd.addNumericField("Area", area, 2);
gd.addChoice("Units", UNITS, units);
}
gd.showDialog();
if (gd.wasCanceled())
return false;
if (!fileInput) {
distance = gd.getNextNumber();
clusteringAlgorithm = sClusteringAlgorithm = ClusteringAlgorithm.values()[gd.getNextChoiceIndex()];
multiThread = gd.getNextBoolean();
if (haveWeights)
weightedClustering = sWeightedClustering = gd.getNextBoolean();
}
minN = (int) Math.abs(gd.getNextNumber());
maxN = (int) Math.abs(gd.getNextNumber());
showCumulativeHistogram = gd.getNextBoolean();
maximumLikelihood = gd.getNextBoolean();
if (!fileInput) {
saveHistogram = gd.getNextBoolean();
calibrateHistogram = gd.getNextBoolean();
frames = (int) Math.abs(gd.getNextNumber());
area = Math.abs(gd.getNextNumber());
units = gd.getNextChoice();
}
// Check arguments
try {
Parameters.isAboveZero("Min N", minN);
if (!fileInput) {
Parameters.isAboveZero("Distance", distance);
Parameters.isAboveZero("Frames", frames);
Parameters.isAboveZero("Area", area);
}
} catch (IllegalArgumentException ex) {
error(ex.getMessage());
return false;
}
return true;
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class PCPALMClusters method loadNoiseHistogram.
/**
* If the histogram is calibrated then ask the user if they wish to subtract a calibrated noise histogram.
* <p>
* Loads a noise histogram from a user selected file and check the units match those provided
*
* @param histogramData
* @return The histogram (or null)
*/
private HistogramData loadNoiseHistogram(HistogramData histogramData) {
if (!histogramData.isCalibrated())
return null;
GenericDialog gd = new GenericDialog(TITLE);
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.addMessage("The histogram is calibrated.\n \nDo you want to subtract a noise histogram before fitting?");
boolean allowSave = new File(histogramData.filename).exists();
if (allowSave)
gd.addCheckbox("Auto_save noise-subtracted histogram", sAutoSave);
// If this is a macro then the dialog will not have Yes or No pressed.
// Add a checkbox that can be read from the macro arguments by ImageJ.
String macroOption = "subtract";
if (IJ.isMacro())
gd.addCheckbox(macroOption, true);
gd.showDialog();
if (!gd.wasOKed())
return null;
if (allowSave)
autoSave = sAutoSave = gd.getNextBoolean();
if (IJ.isMacro()) {
// If the macro option flag is not found then the arguments do not want this to run
if (!gd.getNextBoolean())
return null;
} else {
// Ensure that the 'Yes' result is recorded for macros to detect
Recorder.recordOption(macroOption);
}
noiseFile = Utils.getFilename("Noise_file", noiseFile);
if (noiseFile != null) {
HistogramData data = loadHistogram(noiseFile);
// Check the data is calibrated with the same units
if (data.isCalibrated() && data.units.equalsIgnoreCase(histogramData.units))
return data;
}
return null;
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class PCPALMFitting method getCorrelationResults.
private boolean getCorrelationResults() {
// Option to:
// - load a correlation curve
// - use previous results (if available)
// - select a set of analysis results (if available)
String[] options = new String[] { INPUT_FROM_FILE, "", "" };
int count = 1;
if (previous_gr != null)
options[count++] = INPUT_PREVIOUS;
if (!PCPALMAnalysis.results.isEmpty())
options[count++] = INPUT_ANALYSIS;
options = Arrays.copyOf(options, count);
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("Select the source for the correlation curve");
gd.addChoice("Input", options, inputOption);
gd.showDialog();
if (gd.wasCanceled())
return false;
inputOption = gd.getNextChoice();
if (inputOption.equals(INPUT_PREVIOUS)) {
// In the case of a macro the previous results may be null
if (previous_gr == null)
return false;
gr = previous_gr;
peakDensity = previous_peakDensity;
spatialDomain = previous_spatialDomain;
return true;
} else if (inputOption.equals(INPUT_FROM_FILE)) {
return loadCorrelationCurve();
}
// Fill the results list with analysis results from PCPALM Analysis
ArrayList<CorrelationResult> results = new ArrayList<CorrelationResult>();
if (!selectAnalysisResults(results))
return false;
// We have some results. Convert them to the format used for fitting.
header();
log("Computing combined pair correlation curve (%d datasets)", results.size());
spatialDomain = results.get(0).spatialDomain;
// Get average peak density
peakDensity = 0;
int size = 0;
for (CorrelationResult r : results) {
peakDensity += r.peakDensity;
size = FastMath.max(size, r.gr[0].length);
}
peakDensity /= results.size();
// Combine all selected g(r) curves
gr = combineCurves(results, size);
return true;
}
Aggregations