Search in sources :

Example 51 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class ResultsMatchCalculator method getCoordinates.

/**
	 * Build a map between the peak id (time point) and a list of coordinates
	 * 
	 * @param results
	 * @param integerCoordinates
	 *            True if the values should be rounded down to integers
	 * @return
	 */
public static TIntObjectHashMap<ArrayList<Coordinate>> getCoordinates(List<PeakResult> results, boolean integerCoordinates) {
    TIntObjectHashMap<ArrayList<Coordinate>> coords = new TIntObjectHashMap<ArrayList<Coordinate>>();
    if (results.size() > 0) {
        ResultsMatchCalculator instance = new ResultsMatchCalculator();
        // Do not use HashMap directly to build the coords object since there 
        // will be many calls to getEntry(). Instead sort the results and use 
        // a new list for each time point
        Collections.sort(results);
        int minT = results.get(0).getFrame();
        int maxT = results.get(results.size() - 1).getEndFrame();
        // Create lists
        ArrayList<ArrayList<Coordinate>> tmpCoords = new ArrayList<ArrayList<Coordinate>>(maxT - minT + 1);
        for (int t = minT; t <= maxT; t++) {
            tmpCoords.add(new ArrayList<Coordinate>());
        }
        // Add the results to the lists
        for (PeakResult p : results) {
            final float x, y;
            if (integerCoordinates) {
                x = (int) p.getXPosition();
                y = (int) p.getYPosition();
            } else {
                x = p.getXPosition();
                y = p.getYPosition();
            }
            for (int t = p.getFrame() - minT, i = p.getEndFrame() - p.getFrame() + 1; i-- > 0; t++) tmpCoords.get(t).add(instance.new PeakResultPoint(t + minT, x, y, p));
        }
        // Put in the map
        for (int t = minT, i = 0; t <= maxT; t++, i++) {
            coords.put(t, tmpCoords.get(i));
        }
    }
    return coords;
}
Also used : Coordinate(gdsc.core.match.Coordinate) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) ArrayList(java.util.ArrayList) Point(java.awt.Point) BasePoint(gdsc.core.match.BasePoint) PeakResult(gdsc.smlm.results.PeakResult)

Example 52 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class PeakFit method addSingleFrameOverlay.

private void addSingleFrameOverlay() {
    // If a single frame was processed add the peaks as an overlay if they are in memory
    ImagePlus imp = this.imp;
    if (fitMaxima && singleFrame > 0) {
        if (source instanceof IJImageSource) {
            String title = source.getName();
            imp = WindowManager.getImage(title);
        }
    }
    if (singleFrame > 0 && imp != null) {
        MemoryPeakResults results = null;
        for (PeakResults r : this.results.toArray()) if (r instanceof MemoryPeakResults) {
            results = (MemoryPeakResults) r;
            break;
        }
        if (results == null || results.size() == 0)
            return;
        ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
        gd.enableYesNoCancel();
        gd.hideCancelButton();
        gd.addMessage("Add the fitted localisations as an overlay?");
        gd.showDialog();
        if (!gd.wasOKed())
            return;
        LUT lut = LUTHelper.createLUT(LutColour.ICE);
        Overlay o = new Overlay();
        ArrayList<PeakResult> list = (ArrayList<PeakResult>) results.getResults();
        for (int i = 0, j = results.size() - 1; i < results.size(); i++, j--) {
            PeakResult r = list.get(i);
            PointRoi roi = new PointRoi(r.getXPosition(), r.getYPosition());
            Color c = LUTHelper.getColour(lut, j, results.size());
            roi.setStrokeColor(c);
            roi.setFillColor(c);
            if (imp.getStackSize() > 1)
                roi.setPosition(singleFrame);
            o.add(roi);
        }
        imp.setOverlay(o);
        imp.getWindow().toFront();
    }
}
Also used : Color(java.awt.Color) SystemColor(java.awt.SystemColor) ArrayList(java.util.ArrayList) LUT(ij.process.LUT) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) ImagePlus(ij.ImagePlus) PeakResult(gdsc.smlm.results.PeakResult) ExtendedPeakResult(gdsc.smlm.results.ExtendedPeakResult) IJImageSource(gdsc.smlm.ij.IJImageSource) PeakResults(gdsc.smlm.results.PeakResults) IJTablePeakResults(gdsc.smlm.ij.results.IJTablePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) Overlay(ij.gui.Overlay) PointRoi(ij.gui.PointRoi)

Example 53 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class PulseActivationAnalysis method createActivations.

/**
	 * Creates the activations. This splits the input traces into continuous chains of localisations. Each chain is an
	 * activation. A new activation is created if there are more than the configured number of dark frames since the
	 * last localisation. The start frame for the activation defines the channel the activation is assigned to (this may
	 * be channel 0 if the start frame is not in a pulse start frame).
	 */
private void createActivations() {
    TurboList<Activation> activations = new TurboList<Activation>(traces.length);
    // Activations are only counted if there are at least 
    // n frames between localisations.
    final int n = darkFramesForNewActivation + 1;
    for (Trace trace : traces) {
        // Time-order
        trace.sort();
        ArrayList<PeakResult> points = trace.getPoints();
        // Define the frame for a new activation 
        int nextActivationStartFrame = Integer.MIN_VALUE;
        Trace current = null;
        int channel = 0;
        for (int j = 0; j < points.size(); j++) {
            PeakResult p = points.get(j);
            // Check if this is an activation
            if (p.getFrame() >= nextActivationStartFrame) {
                if (current != null)
                    // Store the last
                    activations.add(new Activation(current, channel));
                // Create a new activation
                current = new Trace(p);
                channel = getChannel(p);
            } else {
                // This is the same chain of localisations
                current.add(p);
            }
            nextActivationStartFrame = p.getEndFrame() + n;
        }
        if (current != null)
            activations.add(new Activation(current, channel));
    }
    save(activations);
}
Also used : Trace(gdsc.smlm.results.Trace) TurboList(gdsc.core.utils.TurboList) PeakResult(gdsc.smlm.results.PeakResult) IdPeakResult(gdsc.smlm.results.IdPeakResult)

Example 54 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class ResultsImageSampler method createResultSamples.

/**
	 * Creates the result samples.
	 * Do this by storing the coordinates at the region index.
	 */
private void createResultSamples() {
    TLongObjectHashMap<ResultsSample> map = new TLongObjectHashMap<ResultsSample>(results.size());
    ResultsSample next = ResultsSample.create(-1);
    for (PeakResult p : results) {
        // Avoid invalid slices
        if (p.getFrame() < 1 || p.getFrame() > stack.getSize())
            continue;
        long index = getIndex(p.getXPosition(), p.getYPosition(), p.getFrame());
        ResultsSample current = map.putIfAbsent(index, next);
        if (current == null) {
            // If the return value is null then this is a new insertion.
            // Set the current value as the one we just added and create the next insertion object.
            current = next;
            current.index = index;
            next = ResultsSample.create(-1);
        }
        current.add(p);
    }
    // Create an array of all the sample entries.
    // This is used to sample regions by density.
    data = new ResultsSample[map.size()];
    map.values(data);
}
Also used : TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) PeakResult(gdsc.smlm.results.PeakResult)

Example 55 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class IJImagePeakResults method addAll.

/*
	 * (non-Javadoc)
	 * 
	 * @see gdsc.utils.fitting.results.PeakResults#addAll(java.util.Collection)
	 */
public void addAll(Collection<PeakResult> results) {
    if (!imageActive)
        return;
    int[] indices = new int[5];
    float[] values = new float[4];
    int nPoints = 0;
    int nValues = 0;
    // Buffer output in batches
    int[] allIndices = new int[100];
    float[] allValues = new float[allIndices.length];
    boolean replace = ((displayFlags & DISPLAY_REPLACE) != 0);
    // We add at most 4 indices for each peak
    int limit = allIndices.length - 4;
    for (PeakResult result : results) {
        float x = mapX(result.getXPosition());
        float y = mapY(result.getYPosition());
        // Check bounds
        if (x < 0 || x >= imageWidth || y < 0 || y >= imageHeight)
            continue;
        if (shouldUpdate(result.getFrame())) {
            addData(nPoints, nValues, allIndices, allValues);
            nPoints = 0;
            nValues = 0;
            updateToFrame(result.getFrame());
        }
        getValue(result.getFrame(), result.params, result.error, x, y, indices, values);
        for (int i = indices[4]; i-- > 0; ) {
            allIndices[nValues] = indices[i];
            allValues[nValues] = values[i];
            nValues++;
        }
        nPoints++;
        if (nValues > limit || replace) {
            addData(nPoints, nValues, allIndices, allValues);
            nPoints = 0;
            nValues = 0;
            updateImage();
            if (!imageActive)
                return;
        }
    }
    // Now add the values to the configured indices
    addData(nPoints, nValues, allIndices, allValues);
    updateImage();
}
Also used : PeakResult(gdsc.smlm.results.PeakResult)

Aggregations

PeakResult (gdsc.smlm.results.PeakResult)89 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)40 ExtendedPeakResult (gdsc.smlm.results.ExtendedPeakResult)18 Rectangle (java.awt.Rectangle)18 ArrayList (java.util.ArrayList)17 IdPeakResult (gdsc.smlm.results.IdPeakResult)13 ImagePlus (ij.ImagePlus)9 Point (java.awt.Point)9 Trace (gdsc.smlm.results.Trace)8 ImageStack (ij.ImageStack)7 FractionClassificationResult (gdsc.core.match.FractionClassificationResult)6 Calibration (gdsc.smlm.results.Calibration)6 PreprocessedPeakResult (gdsc.smlm.results.filter.PreprocessedPeakResult)6 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)6 BasePoint (gdsc.core.match.BasePoint)5 Statistics (gdsc.core.utils.Statistics)5 StoredDataStatistics (gdsc.core.utils.StoredDataStatistics)5 IJImagePeakResults (gdsc.smlm.ij.results.IJImagePeakResults)5 GenericDialog (ij.gui.GenericDialog)5 ImageProcessor (ij.process.ImageProcessor)5