Search in sources :

Example 11 with Plot

use of ij.gui.Plot in project GDSC-SMLM by aherbert.

the class PSFCreator method subtractBackgroundAndWindow.

/**
	 * Subtract the background from the spot, compute the intensity within half the box region distance from the centre
	 * and smooth the intensity profile. In interactive mode the user must choose to accept the profile or reject.
	 * If accepted the smoothed profile is user to normalise the image and then the image is rolled off to zero
	 * using a Tukey window function.
	 * 
	 * @param spot
	 * @param background
	 *            The minimum level, all below this is background and set to zero
	 * @param spotWidth
	 * @param spotHeight
	 * @param n
	 *            The spot number
	 * @param loess
	 *            The smoothing interpolator
	 * @return True if accepted
	 */
private boolean subtractBackgroundAndWindow(float[][] spot, final float background, final int spotWidth, final int spotHeight, double[] centre, LoessInterpolator loess) {
    //ImageWindow imageWindow = new ImageWindow();
    for (int i = 0; i < spot.length; i++) {
        for (int j = 0; j < spot[i].length; j++) spot[i][j] = FastMath.max(spot[i][j] - background, 0);
    }
    // Create a distance map from the centre
    if (lastWidth != spotWidth || lastHeight != spotHeight) {
        final double cx = spotWidth * 0.5;
        final double cy = spotHeight * 0.5;
        minx = FastMath.max(0, (int) (cx - boxRadius * 0.5));
        maxx = FastMath.min(spotWidth, (int) Math.ceil(cx + boxRadius * 0.5));
        miny = FastMath.max(0, (int) (cy - boxRadius * 0.5));
        maxy = FastMath.min(spotHeight, (int) Math.ceil(cy + boxRadius * 0.5));
        // Precompute square distances
        double[] dx2 = new double[maxx - minx + 1];
        for (int x = minx, i = 0; x < maxx; x++, i++) {
            // Use pixel centres with 0.5 offset
            final double dx = x + 0.5 - cx;
            dx2[i] = dx * dx;
        }
        dmap = new boolean[dx2.length * (maxy - miny + 1)];
        final double d2 = boxRadius * boxRadius / 4;
        for (int y = miny, j = 0; y < maxy; y++) {
            final double dy = (y + 0.5 - cy);
            final double dy2 = dy * dy;
            final double limit = d2 - dy2;
            for (int x = minx, i = 0; x < maxx; x++, i++, j++) {
                dmap[j] = (dx2[i] < limit);
            }
        }
        lastWidth = spotWidth;
        lastHeight = spotHeight;
    }
    // Calculate the intensity profile within half the box radius from the centre
    double[] xValues = new double[spot.length];
    double[] yValues = new double[spot.length];
    for (int i = 0; i < spot.length; i++) {
        xValues[i] = i + 1;
        double sum = 0;
        for (int y = miny, j = 0; y < maxy; y++) {
            int index = y * spotWidth + minx;
            for (int x = minx; x < maxx; x++, index++, j++) if (dmap[j])
                sum += spot[i][index];
        }
        yValues[i] = sum;
    }
    double[] newY = loess.smooth(xValues, yValues);
    // falls towards zero at the ends)
    for (int i = 0; i < newY.length; i++) if (newY[i] < 0)
        newY[i] = yValues[i];
    if (interactiveMode) {
        Utils.hide(TITLE_AMPLITUDE);
        Utils.hide(TITLE_PSF_PARAMETERS);
        final int n = (int) centre[4];
        String title = TITLE_INTENSITY;
        Plot plot = new Plot(title, "Slice", "Sum", xValues, yValues);
        plot.setColor(Color.red);
        plot.addPoints(xValues, newY, Plot.LINE);
        plot.setColor(Color.green);
        double[] limits = Maths.limits(yValues);
        plot.drawLine(centre[2], limits[0], centre[2], limits[1]);
        plot.setColor(Color.black);
        plot.addLabel(0, 0, "Spot " + n);
        Utils.display(title, plot);
        GenericDialog gd = new GenericDialog(TITLE);
        gd.enableYesNoCancel();
        gd.hideCancelButton();
        gd.addMessage(String.format("Add spot %d to the PSF?\n(The intensity profile is the sum within half the box region)", n));
        if (yesNoPosition != null) {
            gd.centerDialog(false);
            gd.setLocation(yesNoPosition);
        }
        gd.showDialog();
        yesNoPosition = gd.getLocation();
        if (!gd.wasOKed())
            return false;
    }
    for (int i = 0; i < spot.length; i++) {
        // Normalise
        final float scale = (float) (newY[i] / yValues[i]);
        for (int j = 0; j < spot[i].length; j++) spot[i][j] *= scale;
        // Use a Tukey window to roll-off the image edges
        //spot[i] = imageWindow.applySeperable(spot[i], spotWidth, spotHeight, ImageWindow.WindowFunction.Tukey);
        spot[i] = ImageWindow.applyWindow(spot[i], spotWidth, spotHeight, ImageWindow.WindowFunction.TUKEY);
    }
    return true;
}
Also used : Plot(ij.gui.Plot) GenericDialog(ij.gui.GenericDialog) Point(java.awt.Point) BasePoint(gdsc.core.match.BasePoint)

Example 12 with Plot

use of ij.gui.Plot in project vcell by virtualcell.

the class PlotCellRegionStats method run.

@Override
public void run() {
    Plot plot = new ColorPlot("Cell region mean intensity", "Time", "Mean intensity");
    StringBuilder legendLabels = new StringBuilder();
    for (int i = 0; i < datasets.size(); i++) {
        RandomAccessibleInterval<T> data = datasets.get(i);
        if (data instanceof Dataset) {
            legendLabels.append(((Dataset) data).getName());
            legendLabels.append(": ");
        }
        RandomAccessibleInterval<T> cropped = ops.transform().crop(data, mask);
        displayService.createDisplay(cropped);
    }
}
Also used : ColorPlot(org.vcell.imagej.common.gui.ColorPlot) Dataset(net.imagej.Dataset) Plot(ij.gui.Plot) ColorPlot(org.vcell.imagej.common.gui.ColorPlot)

Aggregations

Plot (ij.gui.Plot)12 BasePoint (gdsc.core.match.BasePoint)4 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)3 PlotWindow (ij.gui.PlotWindow)3 Dataset (net.imagej.Dataset)3 StoredDataStatistics (gdsc.core.utils.StoredDataStatistics)2 GenericDialog (ij.gui.GenericDialog)2 Color (java.awt.Color)2 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)2 Pair (net.imglib2.util.Pair)2 ColorPlot (org.vcell.imagej.common.gui.ColorPlot)2 FractionClassificationResult (gdsc.core.match.FractionClassificationResult)1 FractionalAssignment (gdsc.core.match.FractionalAssignment)1 ImmutableFractionalAssignment (gdsc.core.match.ImmutableFractionalAssignment)1 DoubleData (gdsc.core.utils.DoubleData)1 FastCorrelator (gdsc.core.utils.FastCorrelator)1 StoredData (gdsc.core.utils.StoredData)1 MaximaSpotFilter (gdsc.smlm.filters.MaximaSpotFilter)1 ScoredSpot (gdsc.smlm.ij.plugins.BenchmarkSpotFilter.ScoredSpot)1