Search in sources :

Example 56 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class DarkTimeAnalysis method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    // Require some fit results and selected regions
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "There are no fitting results in memory");
        return;
    }
    if (!showDialog()) {
        return;
    }
    // Assume pixels for now
    final MemoryPeakResults results = ResultsManager.loadInputResults(settings.inputOption, true, DistanceUnit.PIXEL);
    IJ.showStatus("");
    if (MemoryPeakResults.isEmpty(results)) {
        IJ.error(TITLE, "No results could be loaded");
        return;
    }
    if (!results.hasCalibration()) {
        IJ.error(TITLE, "Results are not calibrated");
        return;
    }
    msPerFrame = results.getCalibrationReader().getExposureTime();
    if (!(msPerFrame > 0)) {
        IJ.error(TITLE, "ms/frame must be strictly positive: " + msPerFrame);
        return;
    }
    ImageJUtils.log("%s: %d localisations", TITLE, results.size());
    analyse(results);
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Example 57 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class DensityImage method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    // Require some fit results and selected regions
    final int size = MemoryPeakResults.countMemorySize();
    if (size == 0) {
        IJ.error(TITLE, "There are no fitting results in memory");
        return;
    }
    if (!showDialog()) {
        return;
    }
    MemoryPeakResults results = ResultsManager.loadInputResults(settings.inputOption, false, DistanceUnit.PIXEL, null);
    if (MemoryPeakResults.isEmpty(results)) {
        IJ.error(TITLE, "No results could be loaded");
        IJ.showStatus("");
        return;
    }
    final boolean[] isWithin = new boolean[1];
    results = cropWithBorder(results, isWithin);
    if (results.size() == 0) {
        IJ.error(TITLE, "No results within the crop region");
        IJ.showStatus("");
        return;
    }
    final long start = System.currentTimeMillis();
    IJ.showStatus("Calculating density ...");
    final boolean useAdjustment = settings.adjustForBorder && !isWithin[0];
    final DensityManager dm = createDensityManager(results);
    int[] density = null;
    if (settings.useSquareApproximation) {
        density = dm.calculateSquareDensity(settings.radius, settings.resolution, useAdjustment);
    } else {
        density = dm.calculateDensity(settings.radius, useAdjustment);
    }
    density = cropBorder(results, density);
    // Convert to float
    final ScoreCalculator calc = createCalculator(results);
    final float[] densityScore = calc.calculate(density);
    final int filtered = plotResults(results, densityScore, calc);
    logDensityResults(results, density, settings.radius, filtered);
    if (settings.computeRipleysPlot) {
        computeRipleysPlot(results);
    }
    final double seconds = (System.currentTimeMillis() - start) / 1000.0;
    IJ.showStatus(TITLE + " complete : " + seconds + "s");
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) DensityManager(uk.ac.sussex.gdsc.core.clustering.DensityManager)

Example 58 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class DensityImage method plotResults.

/**
 * Draw an image of the density for each localisation. Optionally filter results below a
 * threshold.
 *
 * @param results the results
 * @param density the density
 * @param scoreCalculator the score calculator
 * @return the number of localisations drawn
 */
private int plotResults(MemoryPeakResults results, float[] density, ScoreCalculator scoreCalculator) {
    // Filter results using 5x higher than average density of the sample in a 150nm radius:
    // Annibale, et al (2011). Identification of clustering artifacts in photoactivated localization
    // microscopy.
    // Nature Methods, 8, pp527-528
    MemoryPeakResults newResults = null;
    // No filtering
    float densityThreshold = Float.NEGATIVE_INFINITY;
    if (settings.filterLocalisations) {
        densityThreshold = scoreCalculator.getThreshold();
        newResults = new MemoryPeakResults();
        newResults.copySettings(results);
        newResults.setName(results.getName() + " Density Filter");
    }
    // Draw an image - Use error so that a floating point value can be used on a single pixel
    final ImageJImagePeakResults image = ImagePeakResultsFactory.createPeakResultsImage(ResultsImageType.DRAW_INTENSITY, false, false, results.getName() + " Density", results.getBounds(), results.getNmPerPixel(), settings.imageScale, 0, (settings.cumulativeImage) ? ResultsImageMode.IMAGE_ADD : ResultsImageMode.IMAGE_MAX);
    image.setDisplayFlags(image.getDisplayFlags() | ImageJImagePeakResults.DISPLAY_NEGATIVES);
    image.setLutName("grays");
    image.setLiveImage(false);
    image.begin();
    final StandardResultProcedure sp = new StandardResultProcedure(newResults, DistanceUnit.PIXEL);
    sp.getXyr();
    for (int i = 0; i < density.length; i++) {
        if (density[i] < densityThreshold) {
            continue;
        }
        image.add(sp.x[i], sp.y[i], density[i]);
        if (newResults != null) {
            newResults.add(sp.peakResults[i]);
        }
    }
    image.end();
    // Add to memory
    if (newResults != null && newResults.size() > 0) {
        MemoryPeakResults.addResults(newResults);
    }
    return image.size();
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) StandardResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.StandardResultProcedure) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults)

Example 59 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class AstigmatismModelManager method fitRegion.

private boolean fitRegion() {
    final int radius = config.getFittingWidth();
    if (pluginSettings.getLogFitProgress()) {
        fitConfig.setLog(ImageJPluginLoggerHelper.getLogger(getClass()));
    }
    // Create a fit engine
    results = new MemoryPeakResults();
    results.setCalibration(fitConfig.getCalibration());
    results.setPsf(fitConfig.getPsf());
    results.setSortAfterEnd(true);
    results.begin();
    final int threadCount = Prefs.getThreads();
    final FitEngine engine = FitEngine.create(config, SynchronizedPeakResults.create(results, threadCount), threadCount, FitQueue.BLOCKING);
    final IJImageSource source = new IJImageSource(imp);
    source.open();
    final Rectangle r1 = new Rectangle(cx - radius, cy - radius, 2 * radius + 1, 2 * radius + 1);
    final Rectangle regionBounds = r1.intersection(new Rectangle(source.getWidth(), source.getHeight()));
    // Fit only a spot in the centre
    final int x = cx - regionBounds.x;
    final int y = cy - regionBounds.y;
    final int[] maxIndices = new int[] { y * regionBounds.width + x };
    final Ticker ticker = ImageJUtils.createTicker(source.getFrames(), threadCount);
    IJ.showStatus("Fitting ...");
    boolean shutdown = false;
    while (!shutdown) {
        // Extract the region from each frame
        final float[] region = source.next(regionBounds);
        if (region == null) {
            break;
        }
        final FitParameters params = new FitParameters();
        params.maxIndices = maxIndices.clone();
        final int slice = (int) ticker.getCurrent();
        final ParameterisedFitJob job = new ParameterisedFitJob(slice, params, slice, region, regionBounds);
        engine.run(job);
        ticker.tick();
        shutdown = IJ.escapePressed();
    }
    if (shutdown) {
        IJ.showStatus("Cancelled");
    }
    engine.end(shutdown);
    results.end();
    IJ.showProgress(1);
    if (!shutdown) {
        ImageJUtils.log("Fit %d/%s", results.size(), TextUtils.pleural(source.getFrames(), "spot"));
    }
    return !shutdown;
}
Also used : FitParameters(uk.ac.sussex.gdsc.smlm.engine.FitParameters) IJImageSource(uk.ac.sussex.gdsc.smlm.ij.IJImageSource) FitEngine(uk.ac.sussex.gdsc.smlm.engine.FitEngine) ParameterisedFitJob(uk.ac.sussex.gdsc.smlm.engine.ParameterisedFitJob) Ticker(uk.ac.sussex.gdsc.core.logging.Ticker) Rectangle(java.awt.Rectangle) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Example 60 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class CalibrateResults method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    if (!showInputDialog()) {
        return;
    }
    final MemoryPeakResults results = ResultsManager.loadInputResults(settings.inputOption, false, null, null);
    if (MemoryPeakResults.isEmpty(results)) {
        IJ.error(TITLE, "No results could be loaded");
        return;
    }
    if (!showDialog(results)) {
        return;
    }
    IJ.showStatus("Calibrated " + results.getName());
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Aggregations

MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)138 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)61 List (java.util.List)47 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)46 IJ (ij.IJ)39 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)39 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)38 PeakResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure)38 ArrayList (java.util.ArrayList)36 AtomicReference (java.util.concurrent.atomic.AtomicReference)36 PlugIn (ij.plugin.PlugIn)34 MathUtils (uk.ac.sussex.gdsc.core.utils.MathUtils)33 Counter (uk.ac.sussex.gdsc.smlm.results.count.Counter)33 ImagePlus (ij.ImagePlus)31 Rectangle (java.awt.Rectangle)31 SimpleArrayUtils (uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils)31 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)28 TextUtils (uk.ac.sussex.gdsc.core.utils.TextUtils)28 SettingsManager (uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager)28 FrameCounter (uk.ac.sussex.gdsc.smlm.results.count.FrameCounter)28