use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class DriftCalculator method applyDriftCorrection.
private void applyDriftCorrection(MemoryPeakResults results, double[][] drift) {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Apply drift correction to in-memory results?");
gd.addChoice("Update_method", UPDATE_METHODS, UPDATE_METHODS[updateMethod]);
// Option to save the drift unless it was loaded from file
if (method != DRIFT_FILE)
gd.addCheckbox("Save_drift", saveDrift);
gd.showDialog();
if (gd.wasCanceled())
return;
updateMethod = gd.getNextChoiceIndex();
if (method != DRIFT_FILE) {
saveDrift = gd.getNextBoolean();
saveDrift(calculatedTimepoints, lastdx, lastdy);
}
if (updateMethod == 0)
return;
final double[] dx = drift[0];
final double[] dy = drift[1];
if (updateMethod == 1) {
// Update the results in memory
Utils.log("Applying drift correction to the results set: " + results.getName());
for (PeakResult r : results) {
r.params[Gaussian2DFunction.X_POSITION] += dx[r.getFrame()];
r.params[Gaussian2DFunction.Y_POSITION] += dy[r.getFrame()];
}
} else {
// Create a new set of results
MemoryPeakResults newResults = new MemoryPeakResults(results.size());
newResults.copySettings(results);
newResults.setName(results.getName() + " (Corrected)");
MemoryPeakResults.addResults(newResults);
final boolean truncate = updateMethod == 3;
Utils.log("Creating %sdrift corrected results set: " + newResults.getName(), (truncate) ? "truncated " : "");
for (PeakResult r : results) {
if (truncate) {
if (r.getFrame() < interpolationStart || r.getFrame() > interpolationEnd)
continue;
}
float[] params = Arrays.copyOf(r.params, r.params.length);
params[Gaussian2DFunction.X_POSITION] += dx[r.getFrame()];
params[Gaussian2DFunction.Y_POSITION] += dy[r.getFrame()];
newResults.addf(r.getFrame(), r.origX, r.origY, r.origValue, r.error, r.noise, params, r.paramsStdDev);
}
}
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class DriftCalculator method showSubImageDialog.
private boolean showSubImageDialog() {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
gd.addMessage("Compute the drift using localisation sub-image alignment");
gd.addNumericField("Frames", frames, 0);
gd.addSlider("Minimum_localisations", 10, 50, minimimLocalisations);
gd.addChoice("FFT size", SIZES, reconstructionSize);
String[] 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 false;
frames = (int) gd.getNextNumber();
minimimLocalisations = (int) gd.getNextNumber();
reconstructionSize = gd.getNextChoice();
subPixelMethod = (gd.getNextChoiceIndex() == 0) ? AlignImagesFFT.SubPixelMethod.CUBIC : AlignImagesFFT.SubPixelMethod.GAUSSIAN;
// Check arguments
try {
Parameters.isAboveZero("Frames", frames);
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return false;
}
return true;
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TraceDiffusion method showDialog.
private boolean showDialog() {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
globalSettings = SettingsManager.loadSettings();
settings = globalSettings.getClusteringSettings();
gd.addCheckbox("Truncate_traces", settings.truncate);
gd.addCheckbox("Internal_distances", settings.internalDistances);
//gd.addCheckbox("Sub-sample_distances", settings.subSampledDistances);
gd.addSlider("Fit_length", 2, 20, settings.fitLength);
gd.addCheckbox("MSD_correction", settings.msdCorrection);
gd.addCheckbox("Precision_correction", settings.precisionCorrection);
gd.addCheckbox("Maximum_likelihood", settings.mle);
gd.addSlider("Fit_restarts", 0, 10, settings.fitRestarts);
gd.addSlider("Jump_distance", 1, 20, settings.jumpDistance);
gd.addSlider("Minimum_difference", 0, 10, minDifference);
gd.addSlider("Minimum_fraction", 0, 1, minFraction);
if (extraOptions)
gd.addSlider("Minimum_N", 1, 10, minN);
gd.addSlider("Maximum_N", 2, 10, maxN);
gd.addCheckbox("Debug_fitting", debugFitting);
gd.addCheckbox("Save_trace_distances", saveTraceDistances);
gd.addCheckbox("Save_raw_data", saveRawData);
gd.addCheckbox("Show_histograms", settings.showHistograms);
gd.addStringField("Title", title);
gd.showDialog();
if (gd.wasCanceled() || !readDialog(gd))
return false;
// Update the settings
SettingsManager.saveSettings(globalSettings);
return true;
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class SplitResults 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;
}
String[] items = Utils.getImageList(Utils.GREY_8_16);
if (items.length == 0) {
IJ.error(TITLE, "There are no suitable mask images");
return;
}
// Show a dialog allowing the results set to be filtered
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Select a dataset to split");
ResultsManager.addInput(gd, inputOption, InputSource.MEMORY);
gd.addChoice("Object_mask", items, objectMask);
gd.addCheckbox("Show_object_mask", showObjectMask);
gd.addCheckbox("Non_mask_dataset", nonMaskDataset);
gd.showDialog();
if (gd.wasCanceled())
return;
inputOption = ResultsManager.getInputSource(gd);
objectMask = gd.getNextChoice();
showObjectMask = gd.getNextBoolean();
nonMaskDataset = gd.getNextBoolean();
MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, false);
if (results == null || results.size() == 0) {
IJ.error(TITLE, "No results could be loaded");
return;
}
ImagePlus imp = WindowManager.getImage(objectMask);
if (imp == null) {
IJ.error(TITLE, "No object mask could be found");
return;
}
splitResults(results, imp.getProcessor());
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TraceDiffusion method calculatePrecision.
/**
* Calculate the average precision of localisation in the traces
*
* @param traces
* @param multi
*/
private void calculatePrecision(Trace[] traces, boolean multi) {
// Check the diffusion simulation for a precision
if (DiffusionRateTest.isSimulated(results.getName()) && !multi) {
precision = DiffusionRateTest.lastSimulatedPrecision;
} else {
// Get the average precision of the localisations
precision = 0;
final double nmPerPixel = results.getNmPerPixel();
final double gain = results.getGain();
final boolean emCCD = results.isEMCCD();
int n = 0;
for (Trace trace : traces) {
for (PeakResult r : trace.getPoints()) precision += r.getPrecision(nmPerPixel, gain, emCCD);
n += trace.size();
}
precision /= n;
}
if (precision > 100) {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("The average precision of the traced results is " + Utils.rounded(precision, 4) + " nm.\nPlease verify the precision.");
gd.addSlider("Precision (nm)", 5, 100, precision);
gd.showDialog();
if (!(gd.wasCanceled() || gd.invalidNumber())) {
precision = Math.abs(gd.getNextNumber());
}
}
}
Aggregations