use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class PSFDrift method showHWHM.
private void showHWHM(List<String> titles) {
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("Select the input PSF image");
gd.addChoice("PSF", titles.toArray(new String[titles.size()]), title);
gd.addCheckbox("Use_offset", useOffset);
gd.addNumericField("Scale", scale, 2);
gd.showDialog();
if (gd.wasCanceled())
return;
title = gd.getNextChoice();
useOffset = gd.getNextBoolean();
scale = gd.getNextNumber();
imp = WindowManager.getImage(title);
if (imp == null) {
IJ.error(TITLE, "No PSF image for image: " + title);
return;
}
psfSettings = getPSFSettings(imp);
if (psfSettings == null) {
IJ.error(TITLE, "No PSF settings for image: " + title);
return;
}
int size = imp.getStackSize();
ImagePSFModel psf = createImagePSF(1, size);
double[] w0 = psf.getAllHWHM0();
double[] w1 = psf.getAllHWHM1();
double[] slice = Utils.newArray(w0.length, 1, 1.0);
// Widths are in pixels
String title = TITLE + " HWHM";
Plot plot = new Plot(title, "Slice", "HWHM (px)");
double[] limits = Maths.limits(w0);
limits = Maths.limits(limits, w1);
plot.setLimits(1, size, 0, limits[1] * 1.05);
plot.setColor(Color.red);
plot.addPoints(slice, w0, Plot.LINE);
plot.setColor(Color.blue);
plot.addPoints(slice, w1, Plot.LINE);
plot.setColor(Color.black);
plot.addLabel(0, 0, "X=red; Y=blue");
Utils.display(title, plot);
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class PSFCombiner method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
// Build a list of suitable images
titles = createImageList();
if (titles.isEmpty()) {
IJ.error(TITLE, "No suitable PSF images");
return;
}
try {
while (selectNextImage()) ;
} catch (Exception e) {
IJ.error(TITLE, e.getMessage());
return;
}
if (input.isEmpty()) {
return;
}
if (input.size() < 2) {
IJ.error(TITLE, "Require at least 2 PSF images to combine");
return;
}
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("Set the maximum z-depth +/- from the PSF centre");
gd.addSlider("Z-depth", 20, 200, zDepth);
gd.showDialog();
if (gd.wasCanceled())
return;
zDepth = Math.abs((int) gd.getNextNumber());
for (PSF psf : input) psf.crop(zDepth);
combineImages();
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class GaussianFit method showDialog.
/*
* (non-Javadoc)
*
* @see ij.plugin.filter.ExtendedPlugInFilter#showDialog(ij.ImagePlus, java.lang.String,
* ij.plugin.filter.PlugInFilterRunner)
*/
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
double[] limits = getLimits(imp.getProcessor());
double minValue = limits[0];
double maxValue = limits[1];
if (background > maxValue)
background = (int) maxValue;
if (background < minValue)
background = (int) minValue;
GenericDialog gd = new GenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
gd.addMessage("Fit 2D Gaussian to identified maxima");
gd.addMessage("--- Image smoothing ---\n" + "- Within a 2n+1 box\n");
gd.addSlider("Smoothing", 0, 4.5, smooth);
gd.addMessage("--- Maxima identification ---\n" + "- Within a 2n+1 box\n");
gd.addSlider("Box_size", 1, 15, boxSize);
gd.addSlider("Background", minValue, maxValue, background);
gd.addSlider("Min_height", 0, maxValue, peakHeight);
gd.addSlider("Fraction_above_background", 0, 1.01, fractionAboveBackground);
gd.addSlider("Min_width", 0, 20, peakWidth);
gd.addSlider("Top_N", 0, 20, topN);
gd.addCheckbox("Block_find_algorithm", blockFindAlgorithm);
gd.addCheckbox("Neighbour_check", neighbourCheck);
gd.addSlider("Border", 0, 15, border);
gd.addMessage("--- Gaussian fitting ---");
Component splitLabel = gd.getMessage();
String[] functionNames = SettingsManager.getNames((Object[]) FitFunction.values());
gd.addChoice("Fit_function", functionNames, functionNames[fitFunction]);
gd.addCheckbox("Fit_background", fitBackground);
String[] criteriaNames = SettingsManager.getNames((Object[]) FitCriteria.values());
gd.addChoice("Fit_criteria", criteriaNames, criteriaNames[fitCriteria]);
gd.addNumericField("Max_iterations", maxIterations, 0);
gd.addNumericField("Significant_digits", significantDigits, 0);
gd.addNumericField("Coord_delta", delta, 4);
gd.addCheckbox("Single_fit", singleFit);
gd.addNumericField("Single_region_size", singleRegionSize, 0);
gd.addNumericField("Initial_StdDev", initialPeakStdDev, 3);
gd.addCheckbox("Log_progress", logProgress);
gd.addCheckbox("Show_deviations", showDeviations);
gd.addCheckbox("Filter_results", filterResults);
gd.addCheckbox("Show_fit", showFit);
gd.addPreviewCheckbox(pfr);
gd.addDialogListener(this);
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() || !dialogItemChanged(gd, null)) {
// imp.getProcessor().reset();
imp.setOverlay(null);
return DONE;
}
return flags;
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class LoadLocalisations method getZDepth.
private boolean getZDepth(MemoryPeakResults results) {
// The z-depth is stored in pixels in the error field
double min = results.getHead().error;
double max = min;
for (PeakResult peak : results.getResults()) {
if (min > peak.error)
min = peak.error;
else if (max < peak.error)
max = peak.error;
}
// No z-depth
if (min == max && min == 0)
return true;
maxz = FastMath.min(maxz, max);
minz = FastMath.max(minz, min);
// Display in nm
final double pp = results.getNmPerPixel();
min *= pp;
max *= pp;
String msg = String.format("%d localisations with %.2f <= z <= %.2f", results.size(), min, max);
min = Math.floor(min);
max = Math.ceil(max);
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage(msg);
gd.addCheckbox("Limit Z-depth", limitZ);
gd.addSlider("minZ", min, max, minz * pp);
gd.addSlider("maxZ", min, max, maxz * pp);
gd.showDialog();
if (gd.wasCanceled() || gd.invalidNumber()) {
return false;
}
myLimitZ = limitZ = gd.getNextBoolean();
minz = gd.getNextNumber() / pp;
maxz = gd.getNextNumber() / pp;
return true;
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class LoadLocalisations method getFields.
private static boolean getFields() {
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("Load delimited localisations");
gd.addStringField("Dataset_name", name, 30);
gd.addMessage("Calibration:");
gd.addNumericField("Pixel_size", pixelPitch, 3, 8, "nm");
gd.addNumericField("Gain", gain, 3, 8, "Count/photon");
gd.addNumericField("Exposure_time", exposureTime, 3, 8, "ms");
gd.addMessage("Records:");
gd.addNumericField("Header_lines", header, 0);
gd.addStringField("Comment", comment);
gd.addStringField("Delimiter", delimiter);
String[] dUnits = SettingsManager.getNames((Object[]) DistanceUnit.values());
gd.addChoice("Distance_unit", dUnits, dUnits[distanceUnit]);
String[] iUnits = SettingsManager.getNames((Object[]) IntensityUnit.values());
gd.addChoice("Intensity_unit", iUnits, iUnits[intensityUnit]);
gd.addMessage("Define the fields:");
Label l = (Label) gd.getMessage();
gd.addNumericField("T", it, 0);
gd.addNumericField("ID", iid, 0);
gd.addNumericField("X", ix, 0);
gd.addNumericField("Y", iy, 0);
gd.addNumericField("Z", iz, 0);
gd.addNumericField("Intensity", ii, 0);
gd.addNumericField("Sx", isx, 0);
gd.addNumericField("Sy", isy, 0);
gd.addNumericField("Precision", ip, 0);
// Rearrange
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 == l) {
xOffset += 2;
// Skip title row
yOffset = yOffset - rowCount + 1;
}
// 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()) {
return false;
}
name = getNextString(gd, name);
pixelPitch = gd.getNextNumber();
gain = gd.getNextNumber();
exposureTime = gd.getNextNumber();
header = (int) gd.getNextNumber();
comment = gd.getNextString();
delimiter = getNextString(gd, delimiter);
distanceUnit = gd.getNextChoiceIndex();
intensityUnit = gd.getNextChoiceIndex();
int[] columns = new int[9];
for (int i = 0; i < columns.length; i++) columns[i] = (int) gd.getNextNumber();
{
int i = 0;
it = columns[i++];
iid = columns[i++];
ix = columns[i++];
iy = columns[i++];
iz = columns[i++];
ii = columns[i++];
isx = columns[i++];
isy = columns[i++];
ip = columns[i++];
}
if (gd.invalidNumber()) {
IJ.error(TITLE, "Invalid number in input fields");
return false;
}
for (int i = 0; i < columns.length; i++) {
if (columns[i] < 0)
continue;
for (int j = i + 1; j < columns.length; j++) {
if (columns[j] < 0)
continue;
if (columns[i] == columns[j]) {
IJ.error(TITLE, "Duplicate indicies: " + columns[i]);
return false;
}
}
}
if (gain <= 0 || pixelPitch <= 0) {
IJ.error(TITLE, "Require positive gain and pixel pitch");
return false;
}
if (ix < 0 || iy < 0) {
IJ.error(TITLE, "Require valid X and Y indices");
return false;
}
return true;
}
Aggregations