use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class PeakFit method getPeakWidth.
private boolean getPeakWidth() {
ExtendedGenericDialog gd = newWizardDialog("Enter the expected peak width in pixels.", "A point source of light will not be focussed perfectly by the microscope but will appear as a spread out peak. This Point Spread Function (PSF) can be modelled using a 2D Gaussian curve.", "An optimised optical system (lens and camera sensor) should have a peak standard deviation of approximately 1 pixel when in focus. This allows the fitting routine to have enough data to identify the centre of the peak without spreading the light over too many pixels (which increases noise).", "The peak width can be estimated using the wavelength of light emitted by the single molecules and the parameters of the microscope. Use a PSF calculator by clicking the checkbox below:");
// Add ability to run the PSF Calculator to get the width
gd.addCheckbox("Run_PSF_calculator", false);
gd.addNumericField("Gaussian_SD", fitConfig.getInitialPeakStdDev0(), 3);
if (Utils.isShowGenericDialog()) {
Checkbox cb = (Checkbox) gd.getCheckboxes().get(0);
cb.addItemListener(this);
textInitialPeakStdDev0 = (TextField) gd.getNumericFields().get(0);
}
gd.showDialog();
if (gd.wasCanceled())
return false;
fitConfig.setInitialPeakStdDev(Math.abs(gd.getNextNumber()));
return true;
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class PeakFit method getPixelPitch.
private boolean getPixelPitch() {
ExtendedGenericDialog gd = newWizardDialog("Enter the size of each pixel. This is required to ensure the dimensions of the image are calibrated.", "E.g. a camera with a 6.45um pixel size and a 60x objective will have a pitch of 6450/60 = 107.5nm.");
// TODO - Add a pop-up calculator...
gd.addNumericField("Calibration (nm/px)", calibration.getNmPerPixel(), 2);
gd.showDialog();
if (gd.wasCanceled())
return false;
calibration.setNmPerPixel(Math.abs(gd.getNextNumber()));
return true;
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class PeakFit method configureSmartFilter.
/**
* Show a dialog to configure the smart filter. The updated settings are saved to the settings file.
* <p>
* If the fit configuration isSmartFilter is not enabled then this method returns true. If it is enabled then a
* dialog is shown to input the configuration for a smart filter. If no valid filter can be created from the input
* then the method returns false.
* <p>
* Note: If the smart filter is successfully configured then the use may want to disable the standard fit
* validation.
*
* @param settings
* the settings
* @param filename
* the filename
* @return true, if successful
*/
public static boolean configureSmartFilter(GlobalSettings settings, String filename) {
FitEngineConfiguration config = settings.getFitEngineConfiguration();
FitConfiguration fitConfig = config.getFitConfiguration();
Calibration calibration = settings.getCalibration();
if (!fitConfig.isSmartFilter())
return true;
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
String xml = fitConfig.getSmartFilterXML();
if (Utils.isNullOrEmpty(xml))
xml = fitConfig.getDefaultSmartFilterXML();
gd.addMessage("Smart filter (used to pick optimum results during fitting)");
gd.addTextAreas(XmlUtils.convertQuotes(xml), null, 8, 60);
// Currently we just collect it here even if not needed
gd.addMessage("Smart filters using precision filtering may require a local background level.\n \nLocal background requires the camera bias:");
gd.addNumericField("Camera_bias (ADUs)", calibration.getBias(), 2);
gd.showDialog();
if (gd.wasCanceled())
return false;
xml = gd.getNextText();
Filter f = DirectFilter.fromXML(xml);
if (f == null || !(f instanceof DirectFilter))
return false;
fitConfig.setDirectFilter((DirectFilter) f);
calibration.setBias(Math.abs(gd.getNextNumber()));
if (filename != null)
SettingsManager.saveSettings(settings, filename);
return true;
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class PeakFit method readDialog.
private boolean readDialog(GlobalSettings settings, ExtendedGenericDialog gd, boolean isCrop) {
// Ignore the template
gd.getNextChoice();
String filename = gd.getNextString();
calibration.setNmPerPixel(Math.abs(gd.getNextNumber()));
calibration.setGain(Math.abs(gd.getNextNumber()));
calibration.setEmCCD(gd.getNextBoolean());
calibration.setExposureTime(Math.abs(gd.getNextNumber()));
// The simple fix is to create a plugin to allow the configuration to be changed for results.
if (isCrop)
ignoreBoundsForNoise = optionIgnoreBoundsForNoise = gd.getNextBoolean();
fitConfig.setInitialPeakStdDev0(gd.getNextNumber());
if (!maximaIdentification) {
fitConfig.setInitialPeakStdDev1(gd.getNextNumber());
fitConfig.setInitialAngleD(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 && !fitMaxima) {
interlacedData = gd.getNextBoolean();
integrateFrames = optionIntegrateFrames = (int) gd.getNextNumber();
}
if (!maximaIdentification) {
fitConfig.setFitSolver(gd.getNextChoiceIndex());
fitConfig.setFitFunction(gd.getNextChoiceIndex());
if (extraOptions)
fitConfig.setBackgroundFitting(gd.getNextBoolean());
config.setFailuresLimit((int) gd.getNextNumber());
config.setIncludeNeighbours(gd.getNextBoolean());
config.setNeighbourHeightThreshold(gd.getNextNumber());
config.setResidualsThreshold(gd.getNextNumber());
fitConfig.setDuplicateDistance(gd.getNextNumber());
fitConfig.setSmartFilter(gd.getNextBoolean());
fitConfig.setDisableSimpleFilter(gd.getNextBoolean());
fitConfig.setCoordinateShiftFactor(gd.getNextNumber());
fitConfig.setSignalStrength(gd.getNextNumber());
fitConfig.setMinPhotons(gd.getNextNumber());
if (extraOptions) {
fitConfig.setNoise(gd.getNextNumber());
config.setNoiseMethod(gd.getNextChoiceIndex());
}
fitConfig.setMinWidthFactor(gd.getNextNumber());
fitConfig.setWidthFactor(gd.getNextNumber());
fitConfig.setPrecisionThreshold(gd.getNextNumber());
}
resultsSettings.logProgress = gd.getNextBoolean();
if (!maximaIdentification)
resultsSettings.showDeviations = gd.getNextBoolean();
resultsSettings.setResultsTable(gd.getNextChoiceIndex());
resultsSettings.setResultsImage(gd.getNextChoiceIndex());
resultsSettings.weightedImage = gd.getNextBoolean();
resultsSettings.equalisedImage = gd.getNextBoolean();
resultsSettings.precision = gd.getNextNumber();
resultsSettings.imageScale = gd.getNextNumber();
if (extraOptions) {
resultsSettings.imageRollingWindow = (int) gd.getNextNumber();
showProcessedFrames = optionShowProcessedFrames = gd.getNextBoolean();
}
resultsSettings.resultsDirectory = gd.getNextString();
resultsSettings.setResultsFileFormat(gd.getNextChoiceIndex());
resultsSettings.resultsInMemory = gd.getNextBoolean();
if (extraOptions)
fractionOfThreads = Math.abs(gd.getNextNumber());
// Save to allow dialog state to be maintained even with invalid parameters
if (SettingsManager.saveSettings(settings, filename))
SettingsManager.saveSettingsFilename(filename);
if (gd.invalidNumber())
return false;
// Check arguments
try {
Parameters.isAboveZero("nm per pixel", calibration.getNmPerPixel());
Parameters.isAboveZero("Gain", calibration.getGain());
Parameters.isAboveZero("Exposure time", calibration.getExposureTime());
Parameters.isAboveZero("Initial SD0", fitConfig.getInitialPeakStdDev0());
if (!maximaIdentification) {
Parameters.isAboveZero("Initial SD1", fitConfig.getInitialPeakStdDev1());
Parameters.isPositive("Initial angle", fitConfig.getInitialAngleD());
}
Parameters.isAboveZero("Search_width", config.getSearch());
Parameters.isAboveZero("Fitting_width", config.getFitting());
Parameters.isPositive("Integrate frames", integrateFrames);
if (!maximaIdentification) {
Parameters.isPositive("Failures limit", config.getFailuresLimit());
Parameters.isPositive("Neighbour height threshold", config.getNeighbourHeightThreshold());
Parameters.isPositive("Residuals threshold", config.getResidualsThreshold());
Parameters.isPositive("Duplicate distance", fitConfig.getDuplicateDistance());
if (!fitConfig.isSmartFilter()) {
Parameters.isPositive("Coordinate Shift factor", fitConfig.getCoordinateShiftFactor());
Parameters.isPositive("Signal strength", fitConfig.getSignalStrength());
Parameters.isPositive("Min photons", fitConfig.getMinPhotons());
}
if (extraOptions)
Parameters.isPositive("Noise", fitConfig.getNoise());
if (!fitConfig.isSmartFilter()) {
Parameters.isPositive("Min width factor", fitConfig.getMinWidthFactor());
Parameters.isPositive("Width factor", fitConfig.getWidthFactor());
Parameters.isPositive("Precision threshold", fitConfig.getPrecisionThreshold());
}
}
if (resultsSettings.getResultsImage() == ResultsImage.SIGNAL_AV_PRECISION || resultsSettings.getResultsImage() == ResultsImage.LOCALISATIONS_AV_PRECISION) {
Parameters.isAboveZero("Image precision", resultsSettings.precision);
}
Parameters.isAboveZero("Image scale", resultsSettings.imageScale);
if (extraOptions)
Parameters.isPositive("Image rolling window", resultsSettings.imageRollingWindow);
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return false;
}
// If precision filtering then we need the camera bias
if (!maximaIdentification) {
if (!configureSmartFilter(settings, filename))
return false;
if (!fitConfig.isSmartFilter() && fitConfig.getPrecisionThreshold() > 0) {
gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Precision filtering can use global noise estimate or local background level.\n \nLocal background requires the camera bias:");
gd.addCheckbox("Local_background", fitConfig.isPrecisionUsingBackground());
gd.addNumericField("Camera_bias (ADUs)", calibration.getBias(), 2);
gd.showDialog();
if (gd.wasCanceled())
return false;
fitConfig.setPrecisionUsingBackground(gd.getNextBoolean());
calibration.setBias(Math.abs(gd.getNextNumber()));
}
}
if (!configureDataFilter(settings, filename, extraOptions))
return false;
// Second dialog for solver dependent parameters
if (!maximaIdentification) {
if (!configureFitSolver(settings, filename, extraOptions))
return false;
}
// Extra parameters are needed for interlaced data
if (interlacedData) {
gd = new ExtendedGenericDialog(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;
}
}
boolean result = SettingsManager.saveSettings(settings, filename, true);
if (!result)
IJ.error(TITLE, "Failed to save settings to file " + filename);
return result;
}
use of ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class PulseActivationAnalysis method isSimulation.
private int isSimulation() {
if (Utils.isExtraOptions()) {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Perform a crosstalk simulation?");
gd.enableYesNoCancel();
gd.showDialog();
if (gd.wasOKed())
return 1;
if (gd.wasCanceled())
return -1;
}
return 0;
}
Aggregations