use of java.awt.TextField 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 java.awt.TextField in project GDSC-SMLM by aherbert.
the class Configuration method showDialog.
/**
* Show the current properties.
*
* @param fitEngineConfiguration the fit engine configuration
* @param save the save
* @return true, if successful
*/
public boolean showDialog(FitEngineConfiguration fitEngineConfiguration, boolean save) {
this.config = fitEngineConfiguration;
fitConfig = config.getFitConfiguration();
pluginSettings = Settings.load();
pluginSettings.save();
final CalibrationReader calibrationReader = fitConfig.getCalibrationReader();
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("fit-configuration"));
gd.addMessage("Configuration settings for the single-molecule localisation microscopy plugins");
final String[] templates = ConfigurationTemplate.getTemplateNames(true);
gd.addChoice("Template", templates, templates[0]);
PeakFit.addCameraOptions(gd, fitConfig);
gd.addNumericField("Calibration (nm/px)", calibrationReader.getNmPerPixel(), 2);
gd.addNumericField("Exposure_time (ms)", calibrationReader.getExposureTime(), 2);
gd.addMessage("--- Gaussian parameters ---");
PeakFit.addPsfOptions(gd, fitConfig);
gd.addMessage("--- Maxima identification ---");
final FitEngineConfigurationProvider provider = this::getFitEngineConfiguration;
PeakFit.addDataFilterOptions(gd, provider);
PeakFit.addSearchOptions(gd, provider);
PeakFit.addBorderOptions(gd, provider);
PeakFit.addFittingOptions(gd, provider);
gd.addMessage("--- Gaussian fitting ---");
gd.addChoice("Fit_solver", SettingsManager.getFitSolverNames(), FitProtosHelper.getName(fitConfig.getFitSolver()));
// Parameters specific to each Fit solver are collected in a second dialog
gd.addNumericField("Fail_limit", config.getFailuresLimit(), 0);
gd.addNumericField("Pass_rate", config.getPassRate(), 2);
gd.addCheckbox("Include_neighbours", config.isIncludeNeighbours());
gd.addSlider("Neighbour_height", 0.01, 1, config.getNeighbourHeightThreshold());
gd.addSlider("Residuals_threshold", 0.01, 1, config.getResidualsThreshold());
PeakFit.addDuplicateDistanceOptions(gd, provider);
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, 4.5, fitConfig.getMaxWidthFactor());
PeakFit.addPrecisionOptions(gd, this::getFitConfiguration);
// Add a mouse listener to the config file field
if (ImageJUtils.isShowGenericDialog()) {
final Vector<TextField> numerics = gd.getNumericFields();
final Vector<Checkbox> checkboxes = gd.getCheckboxes();
final Vector<Choice> choices = gd.getChoices();
final Iterator<TextField> nu = numerics.iterator();
final Iterator<Checkbox> cb = checkboxes.iterator();
final Iterator<Choice> ch = choices.iterator();
final Choice textTemplate = ch.next();
textTemplate.addItemListener(this::itemStateChanged);
textCameraType = ch.next();
textNmPerPixel = nu.next();
textExposure = nu.next();
textPsf = ch.next();
textDataFilterType = ch.next();
textDataFilterMethod = ch.next();
textSmooth = nu.next();
textSearch = nu.next();
textBorder = nu.next();
textFitting = nu.next();
textFitSolver = ch.next();
textFailuresLimit = nu.next();
textPassRate = nu.next();
textIncludeNeighbours = cb.next();
textNeighbourHeightThreshold = nu.next();
textResidualsThreshold = nu.next();
textDuplicateDistance = nu.next();
textSmartFilter = cb.next();
textDisableSimpleFilter = cb.next();
textCoordinateShiftFactor = nu.next();
textSignalStrength = nu.next();
textMinPhotons = nu.next();
textMinWidthFactor = nu.next();
textWidthFactor = nu.next();
textPrecisionThreshold = nu.next();
updateFilterInput();
textSmartFilter.addItemListener(this::itemStateChanged);
textDisableSimpleFilter.addItemListener(this::itemStateChanged);
}
if (save) {
gd.enableYesNoCancel("Save", "Save template");
}
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
// In case a template updated the calibration
final CalibrationWriter calibrationWriter = fitConfig.getCalibrationWriter();
// Ignore the template
gd.getNextChoice();
calibrationWriter.setCameraType(SettingsManager.getCameraTypeValues()[gd.getNextChoiceIndex()]);
calibrationWriter.setNmPerPixel(gd.getNextNumber());
calibrationWriter.setExposureTime(gd.getNextNumber());
fitConfig.setCalibration(calibrationWriter.getCalibration());
fitConfig.setPsfType(PeakFit.getPsfTypeValues()[gd.getNextChoiceIndex()]);
config.setDataFilterType(gd.getNextChoiceIndex());
config.setDataFilter(gd.getNextChoiceIndex(), Math.abs(gd.getNextNumber()), false, 0);
config.setSearch(gd.getNextNumber());
config.setBorder(gd.getNextNumber());
config.setFitting(gd.getNextNumber());
// Some enum values are not supported
fitConfig.setFitSolver(SettingsManager.getFitSolverValues()[gd.getNextChoiceIndex()]);
config.setFailuresLimit((int) gd.getNextNumber());
config.setPassRate(gd.getNextNumber());
config.setIncludeNeighbours(gd.getNextBoolean());
config.setNeighbourHeightThreshold(gd.getNextNumber());
config.setResidualsThreshold(gd.getNextNumber());
config.setDuplicateDistance(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.setMaxWidthFactor(gd.getNextNumber());
fitConfig.setPrecisionThreshold(gd.getNextNumber());
gd.collectOptions();
// Check arguments
try {
ParameterUtils.isAboveZero("nm per pixel", calibrationWriter.getNmPerPixel());
ParameterUtils.isAboveZero("Exposure time", calibrationWriter.getExposureTime());
if (fitConfig.getPsfTypeValue() != PSFType.ASTIGMATIC_GAUSSIAN_2D_VALUE) {
ParameterUtils.isAboveZero("Initial SD0", fitConfig.getInitialXSd());
if (fitConfig.getPsf().getParametersCount() > 1) {
ParameterUtils.isAboveZero("Initial SD1", fitConfig.getInitialYSd());
}
}
ParameterUtils.isAboveZero("Search_width", config.getSearch());
ParameterUtils.isAboveZero("Fitting_width", config.getFitting());
ParameterUtils.isPositive("Neighbour height threshold", config.getNeighbourHeightThreshold());
ParameterUtils.isPositive("Residuals threshold", config.getResidualsThreshold());
ParameterUtils.isPositive("Duplicate distance", config.getDuplicateDistance());
if (!fitConfig.isSmartFilter()) {
ParameterUtils.isPositive("Coordinate Shift factor", fitConfig.getCoordinateShiftFactor());
ParameterUtils.isPositive("Signal strength", fitConfig.getSignalStrength());
ParameterUtils.isPositive("Min photons", fitConfig.getMinPhotons());
ParameterUtils.isPositive("Min width factor", fitConfig.getMinWidthFactor());
ParameterUtils.isPositive("Width factor", fitConfig.getMaxWidthFactor());
ParameterUtils.isPositive("Precision threshold", fitConfig.getPrecisionThreshold());
}
} catch (final IllegalArgumentException ex) {
IJ.error(TITLE, ex.getMessage());
return false;
}
if (gd.invalidNumber()) {
return false;
}
final int flags = PeakFit.FLAG_NO_SAVE;
if (!PeakFit.configurePsfModel(config, flags)) {
return false;
}
if (!PeakFit.configureResultsFilter(config, flags)) {
return false;
}
if (!PeakFit.configureDataFilter(config, flags)) {
return false;
}
PeakFit.configureFitSolver(config, null, null, flags);
if (save) {
final boolean saveToFile = !gd.wasOKed();
if (saveToFile) {
gd = new ExtendedGenericDialog(TITLE);
gd.addFilenameField("Template_filename", pluginSettings.templateFilename);
gd.addMessage("Add notes to the template ...");
gd.addTextAreas(pluginSettings.notes, null, 10, 60);
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
pluginSettings.save();
final String filename = gd.getNextString();
pluginSettings.notes = gd.getNextText();
if (filename != null) {
pluginSettings.templateFilename = FileUtils.replaceExtension(filename, ".txt");
final File file = new File(pluginSettings.templateFilename);
final String name = FileUtils.removeExtension(file.getName());
final TemplateSettings.Builder settings = TemplateSettings.newBuilder();
settings.addNotes(pluginSettings.notes);
settings.setCalibration(fitConfig.getCalibration());
settings.setFitEngineSettings(config.getFitEngineSettings());
// Note: No results settings are currently supported
settings.setPsf(fitConfig.getPsf());
if (!ConfigurationTemplate.saveTemplate(name, settings.build(), file)) {
IJ.error(TITLE, "Failed to save to file: " + pluginSettings.templateFilename);
}
}
} else {
SettingsManager.writeSettings(config, 0);
}
}
return true;
}
use of java.awt.TextField in project GDSC-SMLM by aherbert.
the class DoubletAnalysis method showAnalysisDialog.
/**
* Show analysis dialog.
*
* @return true, if successful
*/
private boolean showAnalysisDialog() {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("doublet-filter-analysis"));
settings = Settings.load();
config = configRef.get().createCopy();
final StringBuilder sb = new StringBuilder("Filters the doublet fits and reports the performance increase\n");
// Show the fitting settings that will effect filters, i.e. fit standard deviation, fit width
final FitConfiguration fitConfig = config.getFitConfiguration();
sb.append("SD0 = ").append(MathUtils.rounded(fitConfig.getInitialXSd())).append("\n");
// sb.append("SD1 =
// ").append(MathUtils.rounded(fitConfig.getInitialPeakStdDev1())).append("\n");
sb.append("Fit Width = ").append(config.getFittingWidth()).append("\n");
gd.addMessage(sb.toString());
// Collect options for filtering
gd.addChoice("Selection_Criteria", Settings.SELECTION_CRITERIAS, settings.selectionCriteria);
filterFitConfig = filterFitConfigRef.get().createCopy();
// Copy the settings used when fitting
filterFitConfig.setCalibration(fitConfig.getCalibration());
filterFitConfig.setPsf(fitConfig.getPsf());
filterFitConfig.setFitSolverSettings(fitConfig.getFitSolverSettings());
final String[] templates = ConfigurationTemplate.getTemplateNames(true);
gd.addChoice("Template", templates, templates[0]);
// Allow the settings from the benchmark analysis to be used
gd.addCheckbox("Benchmark_settings", settings.analysisUseBenchmarkSettings);
gd.addCheckbox("Smart_filter", filterFitConfig.isSmartFilter());
gd.addSlider("Shift_factor", 0.01, 2, filterFitConfig.getCoordinateShiftFactor());
gd.addNumericField("Signal_strength", filterFitConfig.getSignalStrength(), 2);
gd.addNumericField("Min_photons", filterFitConfig.getMinPhotons(), 0);
gd.addSlider("Min_width_factor", 0, 0.99, filterFitConfig.getMinWidthFactor());
gd.addSlider("Max_width_factor", 1.01, 5, filterFitConfig.getMaxWidthFactor());
gd.addNumericField("Precision", filterFitConfig.getPrecisionThreshold(), 2);
gd.addChoice("Precision_method", SettingsManager.getPrecisionMethodNames(), filterFitConfig.getPrecisionMethod().ordinal());
gd.addNumericField("Drift_angle", settings.analysisDriftAngle, 2);
gd.addNumericField("Min_gap", settings.minGap, 2);
// Collect display options
gd.addCheckbox("Show_results", settings.analysisShowResults);
gd.addCheckbox("Show_Jaccard_Plot", settings.showJaccardPlot);
gd.addCheckbox("Use_max_residuals", settings.useMaxResiduals);
gd.addCheckbox("Logging", settings.analysisLogging);
gd.addStringField("Title", settings.analysisTitle);
gd.addCheckbox("Save_template", settings.saveTemplate);
// Add a mouse listener to the config file field
if (ImageJUtils.isShowGenericDialog()) {
final Vector<TextField> numerics = gd.getNumericFields();
final Vector<Checkbox> checkboxes = gd.getCheckboxes();
final Vector<Choice> choices = gd.getChoices();
choices.get(1).addItemListener(this);
checkboxes.get(0).addItemListener(this);
cbSmartFilter = checkboxes.get(1);
final Iterator<TextField> nu = numerics.iterator();
textCoordinateShiftFactor = nu.next();
textSignalStrength = nu.next();
textMinPhotons = nu.next();
textMinWidthFactor = nu.next();
textWidthFactor = nu.next();
textPrecisionThreshold = nu.next();
textPrecisionMethod = choices.get(2);
}
gd.addHelp(HelpUrls.getUrl("doublet-filter-analysis"));
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
if (gd.invalidNumber()) {
return false;
}
settings.selectionCriteria = gd.getNextChoiceIndex();
// Ignore the template
gd.getNextChoice();
settings.analysisUseBenchmarkSettings = gd.getNextBoolean();
filterFitConfig.setSmartFilter(gd.getNextBoolean());
filterFitConfig.setCoordinateShiftFactor(gd.getNextNumber());
filterFitConfig.setSignalStrength(gd.getNextNumber());
filterFitConfig.setMinPhotons(gd.getNextNumber());
filterFitConfig.setMinWidthFactor(gd.getNextNumber());
filterFitConfig.setMaxWidthFactor(gd.getNextNumber());
filterFitConfig.setPrecisionThreshold(gd.getNextNumber());
filterFitConfig.setPrecisionMethod(gd.getNextChoiceIndex());
settings.analysisDriftAngle = gd.getNextNumber();
settings.minGap = gd.getNextNumber();
settings.analysisShowResults = gd.getNextBoolean();
settings.showJaccardPlot = gd.getNextBoolean();
settings.useMaxResiduals = gd.getNextBoolean();
settings.analysisLogging = gd.getNextBoolean();
settings.analysisTitle = gd.getNextString();
settings.saveTemplate = gd.getNextBoolean();
settings.save();
filterFitConfigRef.set(filterFitConfig);
if (gd.invalidNumber()) {
return false;
}
if (settings.analysisUseBenchmarkSettings) {
return updateFilterConfiguration(filterFitConfig);
} else if (filterFitConfig.isSmartFilter()) {
return PeakFit.configureSmartFilter(filterFitConfig);
}
return true;
}
use of java.awt.TextField in project GDSC-SMLM by aherbert.
the class PsfDrift method showHwhm.
private void showHwhm() {
// Build a list of suitable images
final List<String> titles = createImageList(false);
if (titles.isEmpty()) {
IJ.error(TITLE, "No suitable PSF images");
return;
}
final GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("Approximate the volume of the PSF as a Gaussian and\n" + "compute the equivalent Gaussian width.");
settings = Settings.load();
gd.addChoice("PSF", titles.toArray(new String[0]), settings.title);
gd.addCheckbox("Use_offset", settings.useOffset);
gd.addSlider("Smoothing", 0, 0.5, settings.smoothing);
gd.addHelp(HelpUrls.getUrl("psf-hwhm"));
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
settings.title = gd.getNextChoice();
settings.useOffset = gd.getNextBoolean();
settings.smoothing = gd.getNextNumber();
settings.save();
imp = WindowManager.getImage(settings.title);
if (imp == null) {
IJ.error(TITLE, "No PSF image for image: " + settings.title);
return;
}
psfSettings = getPsfSettings(imp);
if (psfSettings == null) {
IJ.error(TITLE, "No PSF settings for image: " + settings.title);
return;
}
final int size = imp.getStackSize();
final ImagePsfModel psf = createImagePsf(1, size, 1);
final double[] w0 = psf.getAllHwhm0();
final double[] w1 = psf.getAllHwhm1();
// Get current centre
final int centre = psfSettings.getCentreImage();
// Extract valid values (some can be NaN)
double[] sw0 = new double[w0.length];
double[] sw1 = new double[w1.length];
final TDoubleArrayList s0 = new TDoubleArrayList(w0.length);
final TDoubleArrayList s1 = new TDoubleArrayList(w0.length);
int c0 = 0;
int c1 = 0;
for (int i = 0; i < w0.length; i++) {
if (Double.isFinite(w0[i])) {
s0.add(i + 1);
sw0[c0++] = w0[i];
}
if (Double.isFinite(w1[i])) {
s1.add(i + 1);
sw1[c1++] = w1[i];
}
}
if (c0 == 0 && c1 == 0) {
IJ.error(TITLE, "No computed HWHM for image: " + settings.title);
return;
}
double[] slice0 = s0.toArray();
sw0 = Arrays.copyOf(sw0, c0);
double[] slice1 = s1.toArray();
sw1 = Arrays.copyOf(sw1, c1);
// Smooth
if (settings.smoothing > 0) {
final LoessInterpolator loess = new LoessInterpolator(settings.smoothing, 1);
sw0 = loess.smooth(slice0, sw0);
sw1 = loess.smooth(slice1, sw1);
}
final TDoubleArrayList minWx = new TDoubleArrayList();
final TDoubleArrayList minWy = new TDoubleArrayList();
for (int i = 0; i < w0.length; i++) {
double weight = 0;
if (Double.isFinite(w0[i])) {
if (Double.isFinite(w1[i])) {
weight = w0[i] * w1[i];
} else {
weight = w0[i] * w0[i];
}
} else if (Double.isFinite(w1[i])) {
weight = w1[i] * w1[i];
}
if (weight != 0) {
minWx.add(i + 1);
minWy.add(Math.sqrt(weight));
}
}
// Smooth the combined line
final double[] cx = minWx.toArray();
double[] cy = minWy.toArray();
if (settings.smoothing > 0) {
final LoessInterpolator loess = new LoessInterpolator(settings.smoothing, 1);
cy = loess.smooth(cx, cy);
}
final int newCentre = SimpleArrayUtils.findMinIndex(cy);
// Convert to FWHM
final double fwhm = psfSettings.getFwhm();
// Widths are in pixels
final String title = TITLE + " HWHM";
final Plot plot = new Plot(title, "Slice", "HWHM (px)");
double[] limits = MathUtils.limits(sw0);
limits = MathUtils.limits(limits, sw1);
final double maxY = limits[1] * 1.05;
plot.setLimits(1, size, 0, maxY);
plot.setColor(Color.red);
plot.addPoints(slice0, sw0, Plot.LINE);
plot.setColor(Color.blue);
plot.addPoints(slice1, sw1, Plot.LINE);
plot.setColor(Color.magenta);
plot.addPoints(cx, cy, Plot.LINE);
plot.setColor(Color.black);
plot.addLabel(0, 0, "X=red; Y=blue, Combined=Magenta");
final PlotWindow pw = ImageJUtils.display(title, plot);
// Show a non-blocking dialog to allow the centre to be updated ...
// Add a label and dynamically update when the centre is moved.
final NonBlockingExtendedGenericDialog gd2 = new NonBlockingExtendedGenericDialog(TITLE);
final double scale = psfSettings.getPixelSize();
// @formatter:off
ImageJUtils.addMessage(gd2, "Update the PSF information?\n \n" + "Current z-centre = %d, FHWM = %s px (%s nm)\n", centre, MathUtils.rounded(fwhm), MathUtils.rounded(fwhm * scale));
// @formatter:on
gd2.addSlider("z-centre", cx[0], cx[cx.length - 1], newCentre);
final TextField tf = gd2.getLastTextField();
gd2.addMessage("");
gd2.addAndGetButton("Reset", event -> tf.setText(Integer.toString(newCentre)));
final Label label = gd2.getLastLabel();
gd2.addCheckbox("Update_centre", settings.updateCentre);
gd2.addCheckbox("Update_HWHM", settings.updateHwhm);
gd2.enableYesNoCancel();
gd2.hideCancelButton();
final UpdateDialogListener dl = new UpdateDialogListener(cx, cy, maxY, newCentre, scale, pw, label);
gd2.addDialogListener(dl);
gd.addHelp(HelpUrls.getUrl("psf-hwhm"));
gd2.showDialog();
if (gd2.wasOKed() && (settings.updateCentre || settings.updateHwhm)) {
final ImagePSF.Builder b = psfSettings.toBuilder();
if (settings.updateCentre) {
b.setCentreImage(dl.centre);
}
if (settings.updateHwhm) {
b.setFwhm(dl.getFwhm());
}
imp.setProperty("Info", ImagePsfHelper.toString(b));
}
}
use of java.awt.TextField in project GDSC-SMLM by aherbert.
the class PsfCreator method showAlignmentDialog.
private boolean showAlignmentDialog() {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("psf-creator"));
gd.addMessage("Use XYZ stack alignment to create a combined PSF");
final CalibrationWriter cw = CalibrationWriter.create(settings.getCalibration());
// These are ignored for reset
gd.addChoice("Alignment_mode", ALIGNMENT_MODE, settings.getAlignmentMode());
gd.addSlider("Z_radius (px)", 0, imp.getStackSize(), settings.getAlignmentZRadius());
gd.addChoice("PSF_type", PSF_TYPE, settings.getPsfType());
gd.addNumericField("nm_per_pixel", cw.getNmPerPixel(), 2, 6, "nm");
gd.addNumericField("nm_per_slice", settings.getNmPerSlice(), 0, 6, "nm");
PeakFit.addCameraOptions(gd, PeakFit.FLAG_NO_GAIN | PeakFit.FLAG_NO_READ_NOISE, cw);
// For reset
final LocalList<TextField> tf = new LocalList<>();
final LocalList<Checkbox> cb = new LocalList<>();
tf.add(gd.addAndGetSlider("Analysis_window", 0, 8, settings.getAnalysisWindow()));
tf.add(gd.addAndGetSlider("Smoothing", 0.1, 0.5, settings.getSmoothing()));
tf.add(gd.addAndGetSlider("CoM_z_window", 0, 8, settings.getComWindow()));
tf.add(gd.addAndGetSlider("CoM_border", 0, 0.5, settings.getComBorder()));
tf.add(gd.addAndGetSlider("Alignment_magnification", 1, 8, settings.getAlignmentMagnification()));
cb.add(gd.addAndGetCheckbox("Smooth_stack_signal", settings.getSmoothStackSignal()));
tf.add(gd.addAndGetSlider("Max_iterations", 1, 20, settings.getMaxIterations()));
if (settings.getInteractiveMode()) {
cb.add(gd.addAndGetCheckbox("Check_alignments", settings.getCheckAlignments()));
}
tf.add(gd.addAndGetNumericField("Sub-pixel_precision", settings.getSubPixelPrecision(), -2));
if (!settings.getInteractiveMode()) {
tf.add(gd.addAndGetNumericField("RMSD_XY_threshold", settings.getRmsdXyThreshold(), -2));
tf.add(gd.addAndGetNumericField("RMSD_Z_threshold", settings.getRmsdZThreshold(), -2));
tf.add(gd.addAndGetNumericField("CoM_shift_threshold", settings.getComShiftThreshold(), -2));
}
if (ImageJUtils.isShowGenericDialog()) {
gd.addAndGetButton("Reset", event -> {
final boolean interactive = PsfCreator.this.settings.getInteractiveMode();
final PSFCreatorSettings defaults = GuiProtosHelper.defaultPSFCreatorSettings;
int ti = 0;
int cbi = 0;
tf.get(ti++).setText(Double.toString(defaults.getAnalysisWindow()));
tf.get(ti++).setText(Double.toString(defaults.getSmoothing()));
tf.get(ti++).setText(Integer.toString(defaults.getComWindow()));
tf.get(ti++).setText(Double.toString(defaults.getComBorder()));
tf.get(ti++).setText(Integer.toString(defaults.getAlignmentMagnification()));
cb.get(cbi++).setState(defaults.getSmoothStackSignal());
tf.get(ti++).setText(Integer.toString(defaults.getMaxIterations()));
if (interactive) {
cb.get(cbi++).setState(defaults.getCheckAlignments());
}
tf.get(ti++).setText(Double.toString(defaults.getSubPixelPrecision()));
if (!interactive) {
tf.get(ti++).setText(Double.toString(defaults.getRmsdXyThreshold()));
tf.get(ti++).setText(Double.toString(defaults.getRmsdZThreshold()));
tf.get(ti++).setText(Double.toString(defaults.getComShiftThreshold()));
}
// Reset later options too
PsfCreator.this.settings.setPsfMagnification(defaults.getPsfMagnification());
PsfCreator.this.settings.setWindow(defaults.getWindow());
PsfCreator.this.settings.setSmoothStackSignal(defaults.getSmoothStackSignal());
PsfCreator.this.settings.setComBorder(defaults.getComBorder());
PsfCreator.this.settings.setCropBorder(0);
PsfCreator.this.settings.setCropStart(0);
PsfCreator.this.settings.setCropEnd(0);
});
}
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
settings.setAlignmentMode(gd.getNextChoiceIndex());
settings.setAlignmentZRadius((int) gd.getNextNumber());
settings.setPsfType(gd.getNextChoiceIndex());
cw.setNmPerPixel(gd.getNextNumber());
settings.setNmPerSlice(gd.getNextNumber());
cw.setCameraType(SettingsManager.getCameraTypeValues()[gd.getNextChoiceIndex()]);
settings.setAnalysisWindow((int) gd.getNextNumber());
settings.setSmoothing(gd.getNextNumber());
settings.setComWindow((int) gd.getNextNumber());
settings.setComBorder(gd.getNextNumber());
settings.setAlignmentMagnification((int) gd.getNextNumber());
settings.setSmoothStackSignal(gd.getNextBoolean());
settings.setMaxIterations((int) gd.getNextNumber());
if (settings.getInteractiveMode()) {
checkAlignments = gd.getNextBoolean();
settings.setCheckAlignments(checkAlignments);
}
settings.setSubPixelPrecision(gd.getNextNumber());
if (!settings.getInteractiveMode()) {
settings.setRmsdXyThreshold(gd.getNextNumber());
settings.setRmsdZThreshold(gd.getNextNumber());
settings.setComShiftThreshold(gd.getNextNumber());
}
gd.collectOptions();
nmPerPixel = cw.getNmPerPixel();
settings.setCalibration(cw.getBuilder());
SettingsManager.writeSettings(settings);
// Check arguments
try {
ParameterUtils.isPositive("nm/pixel", nmPerPixel);
ParameterUtils.isPositive("nm/slice", settings.getNmPerSlice());
// Since we do a local background estimation for each extracted PSF then we
// do not need the bias for non sCMOS cameras.
// if (!cw.isSCMOS())
// Parameters.isAboveZero("Bias", cw.getBias());
ParameterUtils.isEqualOrAbove("Projection magnification", settings.getAlignmentMagnification(), 1);
ParameterUtils.isEqualOrAbove("Max iterations", settings.getMaxIterations(), 1);
ParameterUtils.isEqualOrAbove("PSF magnification", settings.getPsfMagnification(), 1);
ParameterUtils.isAbove("Smoothing", settings.getSmoothing(), 0);
ParameterUtils.isBelow("Smoothing", settings.getSmoothing(), 1);
} catch (final IllegalArgumentException ex) {
IJ.error(TITLE, ex.getMessage());
return false;
}
return true;
}
Aggregations