use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TraceDiffusion method readDialog.
private boolean readDialog(ExtendedGenericDialog gd) {
clusteringSettings.setTruncate(gd.getNextBoolean());
clusteringSettings.setInternalDistances(gd.getNextBoolean());
// settings.subSampledDistances = gd.getNextBoolean();
clusteringSettings.setFitLength((int) Math.abs(gd.getNextNumber()));
clusteringSettings.setMsdCorrection(gd.getNextBoolean());
clusteringSettings.setPrecisionCorrection(gd.getNextBoolean());
clusteringSettings.setMle(gd.getNextBoolean());
settings.significanceLevel = Math.abs(gd.getNextNumber());
clusteringSettings.setFitRestarts((int) Math.abs(gd.getNextNumber()));
clusteringSettings.setJumpDistance((int) Math.abs(gd.getNextNumber()));
settings.minDifference = Math.abs(gd.getNextNumber());
settings.minFraction = Math.abs(gd.getNextNumber());
if (extraOptions) {
myMinN = settings.minN = (int) Math.abs(gd.getNextNumber());
}
settings.maxN = (int) Math.abs(gd.getNextNumber());
settings.debugFitting = gd.getNextBoolean();
settings.saveTraceDistances = gd.getNextBoolean();
settings.saveRawData = gd.getNextBoolean();
clusteringSettings.setShowHistograms(gd.getNextBoolean());
settings.title = gd.getNextString();
if (gd.invalidNumber()) {
return false;
}
if (clusteringSettings.getShowHistograms()) {
gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Select the histograms to display");
gd.addCheckbox("Remove_outliers", clusteringSettings.getRemoveOutliers());
gd.addNumericField("Histogram_bins", clusteringSettings.getHistogramBins(), 0);
for (int i = 0; i < settings.displayHistograms.length; i++) {
gd.addCheckbox(Settings.NAMES[i].replace(' ', '_'), settings.displayHistograms[i]);
}
gd.addCheckbox("MSD/Molecule", settings.displayMsdHistogram);
gd.addCheckbox("D/Molecule", settings.displayDHistogram);
gd.addCheckbox("Trace_length", settings.displayTraceLength);
gd.addCheckbox("Trace_size", settings.displayTraceSize);
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
clusteringSettings.setRemoveOutliers(gd.getNextBoolean());
clusteringSettings.setHistogramBins((int) Math.abs(gd.getNextNumber()));
for (int i = 0; i < settings.displayHistograms.length; i++) {
settings.displayHistograms[i] = gd.getNextBoolean();
}
settings.displayMsdHistogram = gd.getNextBoolean();
settings.displayDHistogram = gd.getNextBoolean();
settings.displayTraceLength = gd.getNextBoolean();
settings.displayTraceSize = gd.getNextBoolean();
}
// Check arguments
try {
// Parameters.isAboveZero("Histogram bins", settings.getHistogramBins());
ParameterUtils.isAbove("Fit length", clusteringSettings.getFitLength(), 1);
ParameterUtils.isAboveZero("Jump distance", clusteringSettings.getJumpDistance());
ParameterUtils.isEqualOrAbove("Maximum N", settings.maxN, myMinN);
if (clusteringSettings.getMle()) {
ParameterUtils.isAboveZero("Significance level", settings.significanceLevel);
}
} catch (final IllegalArgumentException ex) {
IJ.error(TITLE, ex.getMessage());
return false;
}
return true;
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TraceMolecules method getParameters.
private boolean getParameters(int traceCount, double distance) {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(pluginTitle + " Optimiser");
final String msg = String.format("Estimate %d molecules at d=%f, t=1", traceCount, distance);
IJ.log(msg);
gd.addMessage(msg);
gd.addNumericField("Min_Distance_Threshold (px)", settings.getMinDistanceThreshold(), 2);
gd.addNumericField("Max_Distance_Threshold (px)", settings.getMaxDistanceThreshold(), 2);
gd.addNumericField("Min_Time_Threshold (frames)", settings.getMinTimeThreshold(), 0);
gd.addNumericField("Max_Time_Threshold (frames)", settings.getMaxTimeThreshold(), 0);
gd.addSlider("Steps", 1, 20, settings.getOptimiserSteps());
gd.addNumericField("Blinking_rate", settings.getBlinkingRate(), 2);
final String[] plotNames = SettingsManager.getNames((Object[]) OptimiserPlot.values());
gd.addChoice("Plot", plotNames, plotNames[OptimiserPlot.get(settings.getOptimiserPlot()).ordinal()]);
if (altKeyDown) {
gd.addCheckbox("Optimise_blinking", pluginSettings.inputOptimiseBlinkingRate);
}
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
settings.setMinDistanceThreshold(gd.getNextNumber());
settings.setMaxDistanceThreshold(gd.getNextNumber());
settings.setMinTimeThreshold((int) gd.getNextNumber());
settings.setMaxTimeThreshold((int) gd.getNextNumber());
settings.setOptimiserSteps((int) gd.getNextNumber());
settings.setBlinkingRate(gd.getNextNumber());
settings.setOptimiserPlot(gd.getNextChoiceIndex());
if (altKeyDown) {
optimiseBlinkingRate = pluginSettings.inputOptimiseBlinkingRate = gd.getNextBoolean();
}
writeSettings();
if (gd.invalidNumber()) {
return false;
}
if (settings.getMinDistanceThreshold() < 0) {
settings.setMinDistanceThreshold(0);
}
if (settings.getMaxDistanceThreshold() < settings.getMinDistanceThreshold()) {
settings.setMaxDistanceThreshold(settings.getMinDistanceThreshold());
}
if (settings.getMinTimeThreshold() < 0) {
settings.setMinTimeThreshold(0);
}
if (settings.getMaxTimeThreshold() < settings.getMinTimeThreshold()) {
settings.setMaxTimeThreshold(settings.getMinTimeThreshold());
}
if (settings.getOptimiserSteps() < 0) {
settings.setOptimiserSteps(1);
}
if (settings.getBlinkingRate() < MIN_BLINKING_RATE) {
IJ.error(gd.getTitle(), "Blinking rate must be above " + MIN_BLINKING_RATE);
return false;
}
if (settings.getMinDistanceThreshold() == settings.getMaxDistanceThreshold() && settings.getMinTimeThreshold() == settings.getMaxTimeThreshold()) {
IJ.error(gd.getTitle(), "Nothing to optimise");
return false;
}
writeSettings();
return true;
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TraceDiffusion method showTraceDialog.
private boolean showTraceDialog(ArrayList<MemoryPeakResults> allResults) {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("trace-diffusion"));
if (!multiMode) {
ResultsManager.addInput(gd, settings.inputOption, InputSource.MEMORY);
}
clusteringSettings = SettingsManager.readClusteringSettings(0).toBuilder();
gd.addChoice("Mode", TRACE_MODE, clusteringSettings.getTraceDiffusionMode(), new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer value) {
clusteringSettings.setTraceDiffusionMode(value);
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog("Trace diffusion options", null);
// Only 2 modes
if (clusteringSettings.getTraceDiffusionMode() == 1) {
// Dynamic Multiple Target Tracing
final TextField tfD = egd.addAndGetNumericField("Diffusion_coefficient", clusteringSettings.getDiffusionCoefficentMaximum(), 3, 6, "um^2/s");
final TextField tfW = egd.addAndGetNumericField("Temporal_window", clusteringSettings.getTemporalWindow(), 0, 6, "frames");
final TextField tfLdw = egd.addAndGetNumericField("Local_diffusion_weight", clusteringSettings.getLocalDiffusionWeight(), 2);
final TextField tfOiw = egd.addAndGetNumericField("On_intensity_weight", clusteringSettings.getOnIntensityWeight(), 2);
final TextField tfDdf = egd.addAndGetNumericField("Disappearance_decay_factor", clusteringSettings.getDisappearanceDecayFactor(), 0, 6, "frames");
final TextField tfDt = egd.addAndGetNumericField("Disappearance_threshold", clusteringSettings.getDisappearanceThreshold(), 0, 6, "frames");
final Checkbox cbDld = egd.addAndGetCheckbox("Disable_local_diffusion_model", clusteringSettings.getDisableLocalDiffusionModel());
final Checkbox cbDim = egd.addAndGetCheckbox("Disable_intensity_model", clusteringSettings.getDisableIntensityModel());
// Allow reset to defaults
egd.addAndGetButton("Defaults", e -> {
final DmttConfiguration config = DmttConfiguration.newBuilder(1).build();
tfD.setText(String.valueOf(clusteringSettings.getDiffusionCoefficentMaximum()));
tfW.setText(String.valueOf(config.getTemporalWindow()));
tfLdw.setText(String.valueOf(config.getLocalDiffusionWeight()));
tfOiw.setText(String.valueOf(config.getOnIntensityWeight()));
tfDdf.setText(String.valueOf(config.getDisappearanceDecayFactor()));
tfDt.setText(String.valueOf(config.getDisappearanceThreshold()));
cbDld.setState(config.isDisableLocalDiffusionModel());
cbDim.setState(config.isDisableIntensityModel());
});
} else {
// Nearest Neighbour
egd.addNumericField("Distance_Threshold (nm)", clusteringSettings.getDistanceThreshold(), 0);
egd.addNumericField("Distance_Exclusion (nm)", clusteringSettings.getDistanceExclusion(), 0);
}
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
if (clusteringSettings.getTraceDiffusionMode() == 1) {
// Dynamic Multiple Target Tracing
clusteringSettings.setDiffusionCoefficentMaximum(egd.getNextNumber());
clusteringSettings.setTemporalWindow((int) egd.getNextNumber());
clusteringSettings.setLocalDiffusionWeight(egd.getNextNumber());
clusteringSettings.setOnIntensityWeight(egd.getNextNumber());
clusteringSettings.setDisappearanceDecayFactor(egd.getNextNumber());
clusteringSettings.setDisappearanceThreshold((int) egd.getNextNumber());
clusteringSettings.setDisableLocalDiffusionModel(egd.getNextBoolean());
clusteringSettings.setDisableIntensityModel(egd.getNextBoolean());
} else {
// Nearest Neighbour
clusteringSettings.setDistanceThreshold(egd.getNextNumber());
clusteringSettings.setDistanceExclusion(Math.abs(egd.getNextNumber()));
}
return true;
}
});
gd.addSlider("Min_trace_length", 2, 20, clusteringSettings.getMinimumTraceLength());
gd.addCheckbox("Ignore_ends", clusteringSettings.getIgnoreEnds());
gd.addCheckbox("Save_traces", clusteringSettings.getSaveTraces());
gd.showDialog();
if (gd.wasCanceled() || !readTraceDialog(gd)) {
return false;
}
// Update the settings
SettingsManager.writeSettings(clusteringSettings.build());
// Load the results
if (!multiMode) {
final MemoryPeakResults results = ResultsManager.loadInputResults(settings.inputOption, true, null, null);
if (MemoryPeakResults.isEmpty(results)) {
IJ.error(TITLE, "No results could be loaded");
IJ.showStatus("");
return false;
}
if (!checkCalibration(results)) {
return false;
}
allResults.add(results);
}
return true;
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TiffSeriesViewer method run.
@Override
public void run(String arg) {
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
settings = Settings.load();
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addChoice("Mode", Settings.MODE, settings.inputMode, new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer value) {
settings.inputMode = value;
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
// This has limited silent support to fake running in a macro
if (settings.inputMode == 0) {
String dir = null;
final String title = "Select image series ...";
if (silent) {
final String macroOptions = Macro.getOptions();
if (macroOptions != null) {
dir = Macro.getValue(macroOptions, title, null);
}
} else {
dir = ImageJUtils.getDirectory(title, settings.inputDirectory);
}
if (TextUtils.isNullOrEmpty(dir)) {
return false;
}
settings.inputDirectory = dir;
} else {
String file = null;
final String title = "Select image ...";
if (silent) {
final String macroOptions = Macro.getOptions();
if (macroOptions != null) {
file = Macro.getValue(macroOptions, title, null);
}
} else {
file = ImageJUtils.getFilename(title, settings.inputFile);
}
if (TextUtils.isNullOrEmpty(file)) {
return false;
}
settings.inputFile = file;
}
updateLabel();
return true;
}
});
gd.addMessage("");
label = gd.getLastLabel();
if (ImageJUtils.isShowGenericDialog()) {
final Choice choice = gd.getLastChoice();
choice.addItemListener(event -> {
settings.inputMode = choice.getSelectedIndex();
updateLabel();
});
updateLabel();
}
gd.addCheckbox("Log_progress", settings.logProgress);
gd.addChoice("Output_mode", Settings.OUTPUT_MODE, settings.outputMode, new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer value) {
settings.outputMode = value;
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
if (settings.outputMode == 0) {
// Nothing to do
return false;
}
final ExtendedGenericDialog egd = new ExtendedGenericDialog("Output Options");
egd.addNumericField("Slices_per_image", settings.imageCount, 0);
egd.addDirectoryField("Output_directory", settings.outputDirectory);
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
settings.imageCount = (int) egd.getNextNumber();
settings.outputDirectory = egd.getNextString();
updateLabel2();
return true;
}
});
gd.addMessage("");
label2 = gd.getLastLabel();
if (ImageJUtils.isShowGenericDialog()) {
final Choice choice = gd.getLastChoice();
choice.addItemListener(event -> {
settings.outputMode = choice.getSelectedIndex();
updateLabel2();
});
updateLabel2();
}
gd.addHelp(HelpUrls.getUrl("tiff-series-viewer"));
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
settings.inputMode = gd.getNextChoiceIndex();
settings.logProgress = gd.getNextBoolean();
settings.outputMode = gd.getNextChoiceIndex();
settings.save();
SeriesImageSource source;
if (settings.inputMode == 0) {
final SeriesOpener series = new SeriesOpener(settings.inputDirectory);
if (series.getNumberOfImages() == 0) {
IJ.error(TITLE, "No images in the selected directory:\n" + settings.inputDirectory);
return;
}
source = new SeriesImageSource(PeakFit.getName(series.getImageList()), series);
} else {
source = new SeriesImageSource(FileUtils.getName(settings.inputFile), new String[] { settings.inputFile });
}
// No memory buffer
source.setBufferLimit(0);
source.setReadHint(ReadHint.NONSEQUENTIAL);
if (!source.isTiffSeries) {
IJ.error(TITLE, "Not a TIFF image");
return;
}
ImageJUtils.showStatus("Opening TIFF ...");
final TrackProgressAdaptor progress = new TrackProgressAdaptor() {
@Override
public void progress(double fraction) {
IJ.showProgress(fraction);
}
@Override
public void progress(long position, long total) {
IJ.showProgress((double) position / total);
}
@Override
public void log(String format, Object... args) {
if (settings.logProgress) {
ImageJUtils.log(format, args);
}
}
@Override
public void status(String format, Object... args) {
ImageJUtils.showStatus(() -> String.format(format, args));
}
@Override
public boolean isLog() {
return settings.logProgress;
}
};
source.setTrackProgress(progress);
if (!source.open()) {
IJ.error(TITLE, "Cannot open the image");
return;
}
ImageJUtils.showStatus("");
// Create a virtual stack
final TiffSeriesVirtualStack stack = new TiffSeriesVirtualStack(source);
if (settings.outputMode == 0) {
stack.show();
} else {
final int nImages = Math.max(1, settings.imageCount);
final ImagePlus imp = stack.createImp();
// The calibration only has the offset so ignore for speed.
// Calibration cal = imp.getCalibration();
final int size = stack.getSize();
// Create the format string
final int digits = String.format("%d", size).length();
final String format = new File(settings.outputDirectory, imp.getShortTitle() + "%0" + digits + "d.tif").getPath();
IJ.showStatus("Saving image ...");
try {
for (int i = 1; i <= size; i += nImages) {
if (ImageJUtils.isInterrupted()) {
break;
}
ImageJUtils.showSlowProgress(i, size);
final String path = String.format(format, i);
final ImageStack out = new ImageStack(source.getWidth(), source.getHeight());
for (int j = 0, k = i; j < nImages && k <= size; j++, k++) {
out.addSlice(null, stack.getPixels(k));
}
final ImagePlus outImp = new ImagePlus(path, out);
// outImp.setCalibration(cal);
saveAsTiff(outImp, path);
}
IJ.showStatus("Saved image");
} catch (final IOException ex) {
IJ.log(ExceptionUtils.getStackTrace(ex));
IJ.error(TITLE, "Failed to save image: " + ex.getMessage());
IJ.showStatus("Failed to save image");
} finally {
ImageJUtils.clearSlowProgress();
}
}
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class TraceMatchCalculator method showDialog.
private boolean showDialog() {
settings = Settings.load();
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Compare the traced points in results sets\nand computes the match statistics");
ResultsManager.addInput(gd, "Results1", settings.inputOption1, InputSource.MEMORY_MULTI_FRAME);
ResultsManager.addInput(gd, "Results2", settings.inputOption2, InputSource.MEMORY_MULTI_FRAME);
ResultsManager.addInput(gd, "Results3", settings.inputOption3, InputSource.NONE, InputSource.MEMORY_MULTI_FRAME);
gd.addNumericField("Distance", settings.distanceThreshold, 2, 6, "px");
gd.addNumericField("Beta", settings.beta, 2);
gd.addCheckbox("Show_pairs", settings.showPairs);
gd.addChoice("Sort_pairs", Settings.SORT_OPTIONS, settings.sortIndex);
gd.addHelp(HelpUrls.getUrl("trace-match-calculator"));
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
settings.inputOption1 = gd.getNextChoice();
settings.inputOption2 = gd.getNextChoice();
settings.inputOption3 = gd.getNextChoice();
settings.distanceThreshold = gd.getNextNumber();
settings.beta = gd.getNextNumber();
settings.showPairs = gd.getNextBoolean();
settings.sortIndex = gd.getNextChoiceIndex();
settings.save();
// Check arguments
try {
ParameterUtils.isAboveZero("Distance threshold", settings.distanceThreshold);
ParameterUtils.isPositive("Beta", settings.beta);
} catch (final IllegalArgumentException ex) {
IJ.error(TITLE, ex.getMessage());
return false;
}
return true;
}
Aggregations