use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class ConfigurationTemplate method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
if ("images".equals(arg)) {
showTemplateImages();
return;
}
TITLE = "Template Configuration";
GenericDialog gd = new GenericDialog(TITLE);
gd.addCheckbox("Select_standard_templates", selectStandardTemplates);
gd.addCheckbox("Select_custom_directory", selectCustomDirectory);
gd.showDialog();
if (gd.wasCanceled())
return;
selectStandardTemplates = gd.getNextBoolean();
selectCustomDirectory = gd.getNextBoolean();
if (selectStandardTemplates)
loadSelectedStandardTemplates();
if (selectCustomDirectory)
loadTemplatesFromDirectory();
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class ResultsManager method addTableResults.
private void addTableResults(MemoryPeakResults results, PeakResultsList resultsList, boolean showDeviations, boolean showEndFrame) {
if (resultsSettings.getResultsTable() != ResultsTable.NONE) {
IJTablePeakResults r = new IJTablePeakResults(showDeviations);
r.setPeakIdColumnName("Frame");
r.setShowCalibratedValues(resultsSettings.getResultsTable() == ResultsTable.CALIBRATED);
// Get a bias if required
Calibration calibration = results.getCalibration();
if (r.isShowCalibratedValues() && calibration.getBias() == 0) {
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("Calibrated results requires a camera bias");
gd.addNumericField("Camera_bias (ADUs)", calibration.getBias(), 2);
gd.showDialog();
if (!gd.wasCanceled()) {
calibration.setBias(Math.abs(gd.getNextNumber()));
}
}
r.setShowEndFrame(showEndFrame);
resultsList.addOutput(r);
}
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class ResultsManager method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
if (arg != null && arg.startsWith("clear")) {
Collection<MemoryPeakResults> allResults;
boolean removeAll = false;
if (arg.contains("multi")) {
MultiDialog md = new MultiDialog(TITLE, new MultiDialog.MemoryResultsItems());
md.addSelected(selected);
md.showDialog();
if (md.wasCanceled())
return;
selected = md.getSelectedResults();
if (selected.isEmpty())
return;
allResults = new ArrayList<MemoryPeakResults>(selected.size());
for (String name : selected) {
MemoryPeakResults r = MemoryPeakResults.getResults(name);
if (r != null)
allResults.add(r);
}
} else {
removeAll = true;
allResults = MemoryPeakResults.getAllResults();
}
if (allResults.isEmpty())
return;
long memorySize = 0;
int size = 0;
for (MemoryPeakResults results : allResults) {
memorySize += MemoryPeakResults.estimateMemorySize(results.getResults());
size += results.size();
}
String memory = MemoryPeakResults.memorySizeString(memorySize);
String count = Utils.pleural(size, "result");
String sets = Utils.pleural(allResults.size(), "set");
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage(String.format("Do you want to remove %s from memory (%s, %s)?", count, sets, memory));
gd.enableYesNoCancel();
gd.showDialog();
if (!gd.wasOKed())
return;
if (removeAll)
MemoryPeakResults.clearMemory();
else {
for (MemoryPeakResults results : allResults) MemoryPeakResults.removeResults(results.getName());
}
SummariseResults.clearSummaryTable();
IJ.log(String.format("Cleared %s (%s, %s)", count, sets, memory));
return;
}
if (!showDialog())
return;
MemoryPeakResults results = loadResults(inputOption);
if (results == null || results.size() == 0) {
IJ.error(TITLE, "No results could be loaded");
IJ.showStatus("");
return;
}
results = cropToRoi(results);
if (results.size() == 0) {
IJ.error(TITLE, "No results within the crop region");
return;
}
if (resultsSettings.resultsInMemory && fileInput)
MemoryPeakResults.addResults(results);
IJ.showStatus("Processing outputs ...");
Rectangle bounds = results.getBounds(true);
boolean showDeviations = resultsSettings.showDeviations && canShowDeviations(results);
boolean showEndFrame = canShowEndFrame(results);
boolean showId = canShowId(results);
// Display the configured output
PeakResultsList outputList = new PeakResultsList();
outputList.copySettings(results);
//String title = results.getSource();
//if (title == null || title.length() == 0)
// output.setSource(TITLE);
addTableResults(results, outputList, showDeviations, showEndFrame);
addImageResults(outputList, results.getName(), bounds, results.getNmPerPixel(), results.getGain());
addFileResults(outputList, showDeviations, showEndFrame, showId);
// Reduce to single object for speed
PeakResults output = (outputList.numberOfOutputs() == 1) ? outputList.toArray()[0] : outputList;
output.begin();
// Process in batches to provide progress
List<PeakResult> list = results.getResults();
int progress = 0;
int totalProgress = list.size();
int stepProgress = Utils.getProgressInterval(totalProgress);
TurboList<PeakResult> batch = new TurboList<PeakResult>(stepProgress);
for (PeakResult result : list) {
if (progress % stepProgress == 0) {
IJ.showProgress(progress, totalProgress);
}
progress++;
batch.addf(result);
if (batch.size() == stepProgress) {
output.addAll(batch);
batch.clearf();
if (isInterrupted())
break;
}
}
IJ.showProgress(1);
output.end();
IJ.showStatus(String.format("Processed %d result%s", results.size(), (results.size() > 1) ? "s" : ""));
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class PSFEstimator method showDialog.
/**
* @param imp
* @return
*/
private int showDialog(ImagePlus imp) {
// Keep class variables for the parameters we are fitting
FitConfiguration fitConfig = config.getFitConfiguration();
initialPeakStdDev0 = fitConfig.getInitialPeakStdDev0();
initialPeakStdDev1 = fitConfig.getInitialPeakStdDev1();
initialPeakAngle = fitConfig.getInitialAngle();
if (!extraOptions) {
interlacedData = false;
integrateFrames = 1;
}
this.imp = imp;
GenericDialog gd = new GenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
gd.addMessage("Estimate 2D Gaussian to fit maxima");
gd.addNumericField("Initial_StdDev0", initialPeakStdDev0, 3);
gd.addNumericField("Initial_StdDev1", initialPeakStdDev1, 3);
gd.addNumericField("Initial_Angle", initialPeakAngle, 3);
gd.addNumericField("Number_of_peaks", settings.numberOfPeaks, 0);
// pValue sets the smallest significance level probability level at which they are said to be different.
// i.e. p <= pValue they are different
// lower pValue means harder to be found different.
// lower pValue means easier to be found the same.
gd.addNumericField("p-Value", settings.pValue, 4);
gd.addCheckbox("Update_preferences", settings.updatePreferences);
gd.addCheckbox("Log_progress", settings.debugPSFEstimator);
gd.addCheckbox("Iterate", settings.iterate);
gd.addCheckbox("Show_histograms", settings.showHistograms);
gd.addNumericField("Histogram_bins", settings.histogramBins, 0);
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.addSlider("Smoothing", 0, 2.5, config.getSmooth(0));
gd.addSlider("Search_width", 0.5, 2.5, config.getSearch());
gd.addSlider("Border", 0.5, 2.5, config.getBorder());
gd.addSlider("Fitting_width", 2, 4.5, config.getFitting());
if (extraOptions) {
gd.addCheckbox("Interlaced_data", optionInterlacedData);
gd.addSlider("Integrate_frames", 1, 5, optionIntegrateFrames);
}
gd.addMessage("--- Gaussian fitting ---");
Component splitLabel = gd.getMessage();
String[] solverNames = SettingsManager.getNames((Object[]) FitSolver.values());
gd.addChoice("Fit_solver", solverNames, solverNames[fitConfig.getFitSolver().ordinal()]);
String[] functionNames = SettingsManager.getNames((Object[]) FitFunction.values());
gd.addChoice("Fit_function", functionNames, functionNames[fitConfig.getFitFunction().ordinal()]);
// Parameters specific to each Fit solver are collected in a second dialog
gd.addNumericField("Fail_limit", config.getFailuresLimit(), 0);
gd.addCheckbox("Include_neighbours", config.isIncludeNeighbours());
gd.addSlider("Neighbour_height", 0.01, 1, config.getNeighbourHeightThreshold());
gd.addSlider("Residuals_threshold", 0.01, 1, config.getResidualsThreshold());
gd.addMessage("--- Peak filtering ---\nDiscard fits that shift; are too low; or expand/contract");
gd.addCheckbox("Smart_filter", fitConfig.isSmartFilter());
gd.addCheckbox("Disable_simple_filter", fitConfig.isDisableSimpleFilter());
gd.addSlider("Shift_factor", 0.01, 2, fitConfig.getCoordinateShiftFactor());
gd.addNumericField("Signal_strength", fitConfig.getSignalStrength(), 2);
gd.addNumericField("Min_photons", fitConfig.getMinPhotons(), 0);
gd.addSlider("Min_width_factor", 0, 0.99, fitConfig.getMinWidthFactor());
gd.addSlider("Width_factor", 1.01, 5, fitConfig.getWidthFactor());
gd.addNumericField("Precision", fitConfig.getPrecisionThreshold(), 2);
if (gd.getLayout() != null) {
GridBagLayout grid = (GridBagLayout) gd.getLayout();
int xOffset = 0, yOffset = 0;
int lastY = -1, rowCount = 0;
for (Component comp : gd.getComponents()) {
// Check if this should be the second major column
if (comp == splitLabel) {
xOffset += 2;
yOffset -= rowCount;
}
// Reposition the field
GridBagConstraints c = grid.getConstraints(comp);
if (lastY != c.gridy)
rowCount++;
lastY = c.gridy;
c.gridx = c.gridx + xOffset;
c.gridy = c.gridy + yOffset;
c.insets.left = c.insets.left + 10 * xOffset;
c.insets.top = 0;
c.insets.bottom = 0;
grid.setConstraints(comp, c);
}
if (IJ.isLinux())
gd.setBackground(new Color(238, 238, 238));
}
gd.showDialog();
if (gd.wasCanceled() || !readDialog(gd))
return DONE;
return flags;
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class PSFEstimator method readDialog.
private boolean readDialog(GenericDialog gd) {
initialPeakStdDev0 = gd.getNextNumber();
initialPeakStdDev1 = gd.getNextNumber();
initialPeakAngle = gd.getNextNumber();
settings.numberOfPeaks = (int) gd.getNextNumber();
settings.pValue = gd.getNextNumber();
settings.updatePreferences = gd.getNextBoolean();
settings.debugPSFEstimator = gd.getNextBoolean();
settings.iterate = gd.getNextBoolean();
settings.showHistograms = gd.getNextBoolean();
settings.histogramBins = (int) gd.getNextNumber();
config.setDataFilterType(gd.getNextChoiceIndex());
config.setDataFilter(gd.getNextChoiceIndex(), Math.abs(gd.getNextNumber()), 0);
config.setSearch(gd.getNextNumber());
config.setBorder(gd.getNextNumber());
config.setFitting(gd.getNextNumber());
if (extraOptions) {
interlacedData = optionInterlacedData = gd.getNextBoolean();
integrateFrames = optionIntegrateFrames = (int) gd.getNextNumber();
}
FitConfiguration fitConfig = config.getFitConfiguration();
fitConfig.setFitSolver(gd.getNextChoiceIndex());
fitConfig.setFitFunction(gd.getNextChoiceIndex());
config.setFailuresLimit((int) gd.getNextNumber());
config.setIncludeNeighbours(gd.getNextBoolean());
config.setNeighbourHeightThreshold(gd.getNextNumber());
config.setResidualsThreshold(gd.getNextNumber());
fitConfig.setSmartFilter(gd.getNextBoolean());
fitConfig.setDisableSimpleFilter(gd.getNextBoolean());
fitConfig.setCoordinateShiftFactor(gd.getNextNumber());
fitConfig.setSignalStrength(gd.getNextNumber());
fitConfig.setMinPhotons(gd.getNextNumber());
fitConfig.setMinWidthFactor(gd.getNextNumber());
fitConfig.setWidthFactor(gd.getNextNumber());
fitConfig.setPrecisionThreshold(gd.getNextNumber());
if (gd.invalidNumber())
return false;
// Check arguments
try {
Parameters.isAboveZero("Initial SD0", initialPeakStdDev0);
Parameters.isAboveZero("Initial SD1", initialPeakStdDev1);
Parameters.isPositive("Initial angle", initialPeakAngle);
Parameters.isPositive("Number of peaks", settings.numberOfPeaks);
Parameters.isAboveZero("P-value", settings.pValue);
Parameters.isEqualOrBelow("P-value", settings.pValue, 0.5);
if (settings.showHistograms)
Parameters.isAboveZero("Histogram bins", settings.histogramBins);
Parameters.isAboveZero("Search width", config.getSearch());
Parameters.isAboveZero("Fitting width", config.getFitting());
Parameters.isPositive("Failures limit", config.getFailuresLimit());
Parameters.isPositive("Neighbour height threshold", config.getNeighbourHeightThreshold());
Parameters.isPositive("Residuals threshold", config.getResidualsThreshold());
Parameters.isPositive("Coordinate Shift factor", fitConfig.getCoordinateShiftFactor());
Parameters.isPositive("Signal strength", fitConfig.getSignalStrength());
Parameters.isPositive("Min photons", fitConfig.getMinPhotons());
Parameters.isPositive("Min width factor", fitConfig.getMinWidthFactor());
Parameters.isPositive("Width factor", fitConfig.getWidthFactor());
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return false;
}
if (fitConfig.getFitFunction() != FitFunction.FREE && fitConfig.getFitFunction() != FitFunction.FREE_CIRCULAR && fitConfig.getFitFunction() != FitFunction.CIRCULAR) {
String msg = "ERROR: A width-fitting function must be selected (i.e. not fixed-width fitting)";
IJ.error(TITLE, msg);
log(msg);
return false;
}
final String filename = SettingsManager.getSettingsFilename();
SettingsManager.saveSettings(globalSettings, filename);
if (!PeakFit.configureSmartFilter(globalSettings, filename))
return false;
if (!PeakFit.configureDataFilter(globalSettings, filename, false))
return false;
if (!PeakFit.configureFitSolver(globalSettings, filename, false))
return false;
// Extra parameters are needed for interlaced data
if (interlacedData) {
gd = new GenericDialog(TITLE);
gd.addMessage("Interlaced data requires a repeating pattern of frames to process.\n" + "Describe the regular repeat of the data:\n \n" + "Start = The first frame that contains data\n" + "Block = The number of continuous frames containing data\n" + "Skip = The number of continuous frames to ignore before the next data\n \n" + "E.G. 2:9:1 = Data was imaged from frame 2 for 9 frames, 1 frame to ignore, then repeat.");
gd.addNumericField("Start", optionDataStart, 0);
gd.addNumericField("Block", optionDataBlock, 0);
gd.addNumericField("Skip", optionDataSkip, 0);
gd.showDialog();
if (gd.wasCanceled())
return false;
if (!gd.wasCanceled()) {
dataStart = (int) gd.getNextNumber();
dataBlock = (int) gd.getNextNumber();
dataSkip = (int) gd.getNextNumber();
if (dataStart > 0 && dataBlock > 0 && dataSkip > 0) {
// Store options for next time
optionInterlacedData = true;
optionDataStart = dataStart;
optionDataBlock = dataBlock;
optionDataSkip = dataSkip;
}
} else {
interlacedData = false;
}
}
return true;
}
Aggregations