Search in sources :

Example 1 with Spot

use of gdsc.smlm.filters.Spot in project GDSC-SMLM by aherbert.

the class SpotFinderPreview method run.

/*
	 * (non-Javadoc)
	 * 
	 * @see ij.plugin.filter.PlugInFilter#run(ij.process.ImageProcessor)
	 */
public void run(ImageProcessor ip) {
    Rectangle bounds = ip.getRoi();
    MaximaSpotFilter filter = config.createSpotFilter(true);
    // Crop to the ROI
    FloatProcessor fp = ip.crop().toFloat(0, null);
    float[] data = (float[]) fp.getPixels();
    int width = fp.getWidth();
    int height = fp.getHeight();
    Spot[] spots = filter.rank(data, width, height);
    data = filter.getPreprocessedData();
    fp = new FloatProcessor(width, height, data);
    ip = ip.duplicate();
    ip.insert(fp, bounds.x, bounds.y);
    //ip.resetMinAndMax();
    ip.setMinAndMax(fp.getMin(), fp.getMax());
    Overlay o = new Overlay();
    o.add(new ImageRoi(0, 0, ip));
    if (label != null) {
        // Get results for frame
        Coordinate[] actual = ResultsMatchCalculator.getCoordinates(actualCoordinates, imp.getCurrentSlice());
        Coordinate[] predicted = new Coordinate[spots.length];
        for (int i = 0; i < spots.length; i++) {
            predicted[i] = new BasePoint(spots[i].x + bounds.x, spots[i].y + bounds.y);
        }
        // Q. Should this use partial scoring with multi-matches allowed.
        // If so then this needs to be refactored out of the BenchmarkSpotFilter class.
        // TODO - compute AUC and max jaccard and plot			
        // Compute matches
        List<PointPair> matches = new ArrayList<PointPair>(Math.min(actual.length, predicted.length));
        List<Coordinate> FP = new ArrayList<Coordinate>(predicted.length);
        MatchResult result = MatchCalculator.analyseResults2D(actual, predicted, distance * fitConfig.getInitialPeakStdDev0(), null, FP, null, matches);
        // Show scores
        setLabel(String.format("P=%s, R=%s, J=%s", Utils.rounded(result.getPrecision()), Utils.rounded(result.getRecall()), Utils.rounded(result.getJaccard())));
        // Create Rois for TP and FP
        if (showTP) {
            float[] x = new float[matches.size()];
            float[] y = new float[x.length];
            int n = 0;
            for (PointPair pair : matches) {
                BasePoint p = (BasePoint) pair.getPoint2();
                x[n] = p.getX() + 0.5f;
                y[n] = p.getY() + 0.5f;
                n++;
            }
            addRoi(0, o, x, y, n, Color.green);
        }
        if (showFP) {
            float[] x = new float[predicted.length - matches.size()];
            float[] y = new float[x.length];
            int n = 0;
            for (Coordinate c : FP) {
                BasePoint p = (BasePoint) c;
                x[n] = p.getX() + 0.5f;
                y[n] = p.getY() + 0.5f;
                n++;
            }
            addRoi(0, o, x, y, n, Color.red);
        }
    } else {
        float[] x = new float[spots.length];
        float[] y = new float[x.length];
        for (int i = 0; i < spots.length; i++) {
            x[i] = spots[i].x + bounds.x + 0.5f;
            y[i] = spots[i].y + bounds.y + 0.5f;
        }
        PointRoi roi = new PointRoi(x, y);
        // Add options to configure colour and labels
        o.add(roi);
    }
    imp.setOverlay(o);
}
Also used : FloatProcessor(ij.process.FloatProcessor) Spot(gdsc.smlm.filters.Spot) BasePoint(gdsc.core.match.BasePoint) Rectangle(java.awt.Rectangle) ArrayList(java.util.ArrayList) ImageRoi(ij.gui.ImageRoi) MatchResult(gdsc.core.match.MatchResult) BasePoint(gdsc.core.match.BasePoint) Coordinate(gdsc.core.match.Coordinate) MaximaSpotFilter(gdsc.smlm.filters.MaximaSpotFilter) PointPair(gdsc.core.match.PointPair) Overlay(ij.gui.Overlay) PointRoi(ij.gui.PointRoi)

Aggregations

BasePoint (gdsc.core.match.BasePoint)1 Coordinate (gdsc.core.match.Coordinate)1 MatchResult (gdsc.core.match.MatchResult)1 PointPair (gdsc.core.match.PointPair)1 MaximaSpotFilter (gdsc.smlm.filters.MaximaSpotFilter)1 Spot (gdsc.smlm.filters.Spot)1 ImageRoi (ij.gui.ImageRoi)1 Overlay (ij.gui.Overlay)1 PointRoi (ij.gui.PointRoi)1 FloatProcessor (ij.process.FloatProcessor)1 Rectangle (java.awt.Rectangle)1 ArrayList (java.util.ArrayList)1