Search in sources :

Example 41 with PeakResult

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

the class BenchmarkFilterAnalysis method getCoordinates.

private TIntObjectHashMap<IdPeakResult[]> getCoordinates(List<PeakResult> list) {
    final TIntObjectHashMap<IdPeakResult[]> coords = new TIntObjectHashMap<IdPeakResult[]>();
    if (list.size() > 0) {
        // 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(list);
        int last = -1;
        int id = 0;
        int uniqueId = 0;
        ArrayList<PeakResult> tmp = new ArrayList<PeakResult>();
        // Add the results to the lists
        for (PeakResult p : list) {
            if (last != p.getFrame()) {
                if (!tmp.isEmpty()) {
                    coords.put(last, tmp.toArray(new IdPeakResult[tmp.size()]));
                }
                id = 0;
                tmp.clear();
            }
            last = p.getFrame();
            tmp.add(new IdPeakResult(id++, uniqueId++, p));
        }
        if (!tmp.isEmpty()) {
            coords.put(last, tmp.toArray(new IdPeakResult[tmp.size()]));
        }
    }
    return coords;
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) ArrayList(java.util.ArrayList) PeakResult(gdsc.smlm.results.PeakResult) BasePreprocessedPeakResult(gdsc.smlm.results.filter.BasePreprocessedPeakResult) PreprocessedPeakResult(gdsc.smlm.results.filter.PreprocessedPeakResult)

Example 42 with PeakResult

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

the class BenchmarkSpotFilter method run.

private BenchmarkFilterResult run(FitEngineConfiguration config, boolean relativeDistances, boolean batchSummary) {
    if (Utils.isInterrupted())
        return null;
    MaximaSpotFilter spotFilter = config.createSpotFilter(relativeDistances);
    // Extract all the results in memory into a list per frame. This can be cached
    if (// || lastRelativeDistances != relativeDistances)
    lastId != simulationParameters.id) {
        // Always use float coordinates.
        // The Worker adds a pixel offset for the spot coordinates.
        TIntObjectHashMap<ArrayList<Coordinate>> coordinates = ResultsMatchCalculator.getCoordinates(results.getResults(), false);
        actualCoordinates = new TIntObjectHashMap<PSFSpot[]>();
        lastId = simulationParameters.id;
        //lastRelativeDistances = relativeDistances;
        // Store these so we can reset them
        final int total = totalProgress;
        final String prefix = progressPrefix;
        // Spot PSFs may overlap so we must determine the amount of signal overlap and amplitude effect 
        // for each spot...
        IJ.showStatus("Computing PSF overlap ...");
        final int nThreads = Prefs.getThreads();
        final BlockingQueue<Integer> jobs = new ArrayBlockingQueue<Integer>(nThreads * 2);
        List<OverlapWorker> workers = new LinkedList<OverlapWorker>();
        List<Thread> threads = new LinkedList<Thread>();
        for (int i = 0; i < nThreads; i++) {
            OverlapWorker worker = new OverlapWorker(jobs, coordinates);
            Thread t = new Thread(worker);
            workers.add(worker);
            threads.add(t);
            t.start();
        }
        // Process the frames
        totalProgress = coordinates.size();
        stepProgress = Utils.getProgressInterval(totalProgress);
        progress = 0;
        coordinates.forEachKey(new TIntProcedure() {

            public boolean execute(int value) {
                put(jobs, value);
                return true;
            }
        });
        // Finish all the worker threads by passing in a null job
        for (int i = 0; i < threads.size(); i++) {
            put(jobs, -1);
        }
        // Wait for all to finish
        for (int i = 0; i < threads.size(); i++) {
            try {
                threads.get(i).join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            actualCoordinates.putAll(workers.get(i).coordinates);
        }
        threads.clear();
        IJ.showProgress(-1);
        IJ.showStatus("");
        setupProgress(total, prefix);
    }
    if (!batchMode)
        IJ.showStatus("Computing results ...");
    final ImageStack stack = imp.getImageStack();
    float background = 0;
    if (spotFilter.isAbsoluteIntensity()) {
        // To allow the signal factor to be computed we need to lower the image by the background so 
        // that the intensities correspond to the results amplitude.
        // Just assume the background is uniform.
        double sum = 0;
        for (PeakResult r : results) sum += r.getBackground();
        background = (float) (sum / results.size());
    }
    // Create a pool of workers
    final int nThreads = Prefs.getThreads();
    BlockingQueue<Integer> jobs = new ArrayBlockingQueue<Integer>(nThreads * 2);
    List<Worker> workers = new LinkedList<Worker>();
    List<Thread> threads = new LinkedList<Thread>();
    for (int i = 0; i < nThreads; i++) {
        Worker worker = new Worker(jobs, stack, spotFilter, background);
        Thread t = new Thread(worker);
        workers.add(worker);
        threads.add(t);
        t.start();
    }
    // Fit the frames
    for (int i = 1; i <= stack.getSize(); i++) {
        put(jobs, i);
    }
    // Finish all the worker threads by passing in a null job
    for (int i = 0; i < threads.size(); i++) {
        put(jobs, -1);
    }
    // Wait for all to finish
    for (int i = 0; i < threads.size(); i++) {
        try {
            threads.get(i).join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    threads.clear();
    if (Utils.isInterrupted())
        return null;
    if (!batchMode) {
        IJ.showProgress(-1);
        IJ.showStatus("Collecting results ...");
    }
    TIntObjectHashMap<FilterResult> filterResults = new TIntObjectHashMap<FilterResult>();
    time = 0;
    for (Worker w : workers) {
        time += w.time;
        filterResults.putAll(w.results);
    }
    // Show a table of the results
    BenchmarkFilterResult filterResult = summariseResults(filterResults, config, spotFilter, relativeDistances, batchSummary);
    if (!batchMode)
        IJ.showStatus("");
    return filterResult;
}
Also used : TIntProcedure(gnu.trove.procedure.TIntProcedure) ArrayList(java.util.ArrayList) PeakResult(gdsc.smlm.results.PeakResult) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) MaximaSpotFilter(gdsc.smlm.filters.MaximaSpotFilter) ImageStack(ij.ImageStack) PeakResultPoint(gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint) BasePoint(gdsc.core.match.BasePoint) LinkedList(java.util.LinkedList) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap)

Example 43 with PeakResult

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

the class PCPALMMolecules method getLifetime.

/**
	 * Get the lifetime of the results using the earliest and latest frames and the calibrated exposure time.
	 */
private void getLifetime() {
    int start;
    int end;
    List<PeakResult> peakResults = results.getResults();
    if (peakResults.isEmpty()) {
        seconds = 0;
        return;
    }
    start = end = peakResults.get(0).getFrame();
    for (PeakResult r : peakResults) {
        if (start > r.getFrame())
            start = r.getFrame();
        if (end < r.getEndFrame())
            end = r.getEndFrame();
    }
    seconds = (end - start + 1) * results.getCalibration().getExposureTime() / 1000;
}
Also used : WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint) ClusterPoint(gdsc.core.clustering.ClusterPoint) PeakResult(gdsc.smlm.results.PeakResult)

Example 44 with PeakResult

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

the class PCPALMMolecules method extractLocalisations.

/**
	 * Extract molecules for the PC-PALM analysis.
	 * <p>
	 * Estimate the localisation uncertainty (precision) of each molecule using the formula of Mortensen, et al (2010),
	 * Nature Methods 7, 377-381. Store distance in nm and signal in photons using the calibration
	 * 
	 * @param results
	 * @return
	 */
public ArrayList<Molecule> extractLocalisations(MemoryPeakResults results) {
    ArrayList<Molecule> molecules = new ArrayList<Molecule>(results.size());
    final double nmPerPixel = results.getNmPerPixel();
    final double gain = results.getGain();
    final boolean emCCD = results.isEMCCD();
    for (PeakResult r : results.getResults()) {
        double p = r.getPrecision(nmPerPixel, gain, emCCD);
        // Remove EMCCD adjustment
        //p /= Math.sqrt(PeakResult.F);
        molecules.add(new Molecule(r.getXPosition() * nmPerPixel, r.getYPosition() * nmPerPixel, p, r.getSignal() / gain));
    }
    return molecules;
}
Also used : TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) ArrayList(java.util.ArrayList) PeakResult(gdsc.smlm.results.PeakResult)

Example 45 with PeakResult

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

the class PCPALMMolecules method cropToRoi.

private MemoryPeakResults cropToRoi(MemoryPeakResults results) {
    Rectangle bounds = results.getBounds(true);
    area = (bounds.width * bounds.height * results.getNmPerPixel() * results.getNmPerPixel()) / 1e6;
    if (roiBounds == null) {
        return results;
    }
    // Adjust bounds relative to input results image
    double xscale = (double) roiImageWidth / bounds.width;
    double yscale = (double) roiImageHeight / bounds.height;
    roiBounds.x /= xscale;
    roiBounds.width /= xscale;
    roiBounds.y /= yscale;
    roiBounds.height /= yscale;
    float minX = (int) (roiBounds.x);
    float maxX = (int) Math.ceil(roiBounds.x + roiBounds.width);
    float minY = (int) (roiBounds.y);
    float maxY = (int) Math.ceil(roiBounds.y + roiBounds.height);
    // Update the area with the cropped region
    area *= (maxX - minX) / bounds.width;
    area *= (maxY - minY) / bounds.height;
    // Create a new set of results within the bounds
    MemoryPeakResults newResults = new MemoryPeakResults();
    newResults.begin();
    for (PeakResult peakResult : results.getResults()) {
        float x = peakResult.params[Gaussian2DFunction.X_POSITION];
        float y = peakResult.params[Gaussian2DFunction.Y_POSITION];
        if (x < minX || x > maxX || y < minY || y > maxY)
            continue;
        newResults.add(peakResult);
    }
    newResults.end();
    newResults.copySettings(results);
    newResults.setBounds(new Rectangle((int) minX, (int) minY, (int) (maxX - minX), (int) (maxY - minY)));
    return newResults;
}
Also used : Rectangle(java.awt.Rectangle) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) 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