Search in sources :

Example 86 with Color

use of java.awt.Color in project GDSC-SMLM by aherbert.

the class FIRE method showDialog.

private boolean showDialog() {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Compute the resolution using Fourier Ring Correlation");
    gd.addHelp(About.HELP_URL);
    boolean single = results2 == null;
    gd.addMessage("Image construction options:");
    gd.addChoice("Image_scale", SCALE_ITEMS, SCALE_ITEMS[imageScaleIndex]);
    gd.addChoice("Auto_image_size", IMAGE_SIZE_ITEMS, IMAGE_SIZE_ITEMS[imageSizeIndex]);
    if (extraOptions)
        gd.addCheckbox("Use_signal (if present)", useSignal);
    gd.addNumericField("Max_per_bin", maxPerBin, 0);
    gd.addMessage("Fourier options:");
    String[] fourierMethodNames = SettingsManager.getNames((Object[]) FRC.FourierMethod.values());
    gd.addChoice("Fourier_method", fourierMethodNames, fourierMethodNames[fourierMethodIndex]);
    String[] samplingMethodNames = SettingsManager.getNames((Object[]) FRC.SamplingMethod.values());
    gd.addChoice("Sampling_method", samplingMethodNames, samplingMethodNames[samplingMethodIndex]);
    gd.addSlider("Sampling_factor", 0.2, 4, perimeterSamplingFactor);
    gd.addMessage("FIRE options:");
    String[] thresholdMethodNames = SettingsManager.getNames((Object[]) FRC.ThresholdMethod.values());
    gd.addChoice("Threshold_method", thresholdMethodNames, thresholdMethodNames[thresholdMethodIndex]);
    gd.addCheckbox("Show_FRC_curve", showFRCCurve);
    if (single) {
        gd.addMessage("For single datasets:");
        Label l = (Label) gd.getMessage();
        gd.addNumericField("Block_size", blockSize, 0);
        gd.addCheckbox("Random_split", randomSplit);
        gd.addNumericField("Repeats", repeats, 0);
        gd.addCheckbox("Show_FRC_curve_repeats", showFRCCurveRepeats);
        gd.addCheckbox("Show_FRC_time_evolution", showFRCTimeEvolution);
        gd.addCheckbox("Spurious correlation correction", spuriousCorrelationCorrection);
        gd.addNumericField("Q-value", qValue, 3);
        gd.addNumericField("Precision_Mean", mean, 2, 6, "nm");
        gd.addNumericField("Precision_Sigma", sigma, 2, 6, "nm");
        if (extraOptions)
            gd.addNumericField("Threads", getLastNThreads(), 0);
        // Rearrange the dialog
        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;
    imageScaleIndex = gd.getNextChoiceIndex();
    imageSizeIndex = gd.getNextChoiceIndex();
    if (extraOptions)
        myUseSignal = useSignal = gd.getNextBoolean();
    maxPerBin = Math.abs((int) gd.getNextNumber());
    fourierMethodIndex = gd.getNextChoiceIndex();
    fourierMethod = FourierMethod.values()[fourierMethodIndex];
    samplingMethodIndex = gd.getNextChoiceIndex();
    samplingMethod = SamplingMethod.values()[samplingMethodIndex];
    perimeterSamplingFactor = gd.getNextNumber();
    thresholdMethodIndex = gd.getNextChoiceIndex();
    thresholdMethod = FRC.ThresholdMethod.values()[thresholdMethodIndex];
    showFRCCurve = gd.getNextBoolean();
    if (single) {
        blockSize = Math.max(1, (int) gd.getNextNumber());
        randomSplit = gd.getNextBoolean();
        repeats = Math.max(1, (int) gd.getNextNumber());
        showFRCCurveRepeats = gd.getNextBoolean();
        showFRCTimeEvolution = gd.getNextBoolean();
        spuriousCorrelationCorrection = gd.getNextBoolean();
        qValue = Math.abs(gd.getNextNumber());
        mean = Math.abs(gd.getNextNumber());
        sigma = Math.abs(gd.getNextNumber());
        if (extraOptions) {
            setThreads((int) gd.getNextNumber());
            lastNThreads = this.nThreads;
        }
    }
    // Check arguments
    try {
        Parameters.isAboveZero("Perimeter sampling factor", perimeterSamplingFactor);
        if (single && spuriousCorrelationCorrection) {
            Parameters.isAboveZero("Q-value", qValue);
            Parameters.isAboveZero("Precision Mean", mean);
            Parameters.isAboveZero("Precision Sigma", sigma);
            // Set these for use in FIRE computation 
            setCorrectionParameters(qValue, mean, sigma);
        }
    } catch (IllegalArgumentException e) {
        IJ.error(TITLE, e.getMessage());
        return false;
    }
    return true;
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) Color(java.awt.Color) Label(java.awt.Label) NonBlockingExtendedGenericDialog(ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) Component(java.awt.Component) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint)

Example 87 with Color

use of java.awt.Color 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;
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) GenericDialog(ij.gui.GenericDialog) Color(java.awt.Color) Component(java.awt.Component)

Example 88 with Color

use of java.awt.Color in project GDSC-SMLM by aherbert.

the class GaussianFit method setOverlay.

/**
	 * Show the points as an overlay
	 * 
	 * @param nMaxima
	 * @param xpoints
	 * @param ypoints
	 */
private void setOverlay(int nMaxima, int[] xpoints, int[] ypoints) {
    PointRoi roi = new PointRoi(xpoints, ypoints, nMaxima);
    Color strokeColor = Color.yellow;
    Color fillColor = Color.green;
    roi.setStrokeColor(strokeColor);
    roi.setFillColor(fillColor);
    roi.setShowLabels(false);
    imp.setOverlay(roi, strokeColor, 2, fillColor);
}
Also used : Color(java.awt.Color) PointRoi(ij.gui.PointRoi)

Example 89 with Color

use of java.awt.Color 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;
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) GenericDialog(ij.gui.GenericDialog) Color(java.awt.Color) Label(java.awt.Label) Component(java.awt.Component)

Example 90 with Color

use of java.awt.Color in project aima-java by aimacode.

the class MapViewPane method paintPreview.

/**
	 * Draws the off-screen image if exists at position (dx, dy) scaled by the
	 * specified factor.
	 */
private void paintPreview(int dx, int dy, float zoomfactor) {
    if (image != null) {
        Graphics2D g2 = (Graphics2D) getGraphics();
        UColor bg = getRenderer().getBackgroundColor();
        g2.setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue(), bg.getAlpha()));
        int newWidth = Math.round(image.getWidth(null) * zoomfactor);
        int newHeight = (int) Math.round(image.getHeight(null) * zoomfactor);
        g2.drawImage(image, dx, dy, newWidth, newHeight, null);
        if (dx > 0)
            g2.clearRect(0, 0, dx, getHeight());
        else
            g2.clearRect(getWidth() + dx, 0, getWidth(), getHeight());
        if (dy > 0)
            g2.clearRect(0, 0, getWidth(), dy);
        else
            g2.clearRect(0, getHeight() + dy, getWidth(), getHeight());
    }
}
Also used : Color(java.awt.Color) Graphics2D(java.awt.Graphics2D)

Aggregations

Color (java.awt.Color)2973 Graphics2D (java.awt.Graphics2D)396 Font (java.awt.Font)250 BufferedImage (java.awt.image.BufferedImage)236 Dimension (java.awt.Dimension)193 JPanel (javax.swing.JPanel)193 Point (java.awt.Point)188 BasicStroke (java.awt.BasicStroke)177 ArrayList (java.util.ArrayList)173 Test (org.junit.Test)156 JLabel (javax.swing.JLabel)148 Paint (java.awt.Paint)140 Rectangle (java.awt.Rectangle)109 GradientPaint (java.awt.GradientPaint)108 Insets (java.awt.Insets)103 GridBagConstraints (java.awt.GridBagConstraints)96 IOException (java.io.IOException)96 Stroke (java.awt.Stroke)94 JScrollPane (javax.swing.JScrollPane)93 File (java.io.File)89