Search in sources :

Example 11 with XyrResultProcedure

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

the class PcPalmMolecules method cropToRoi.

private MemoryPeakResults cropToRoi(MemoryPeakResults results) {
    final Rectangle bounds = results.getBounds(true);
    settings.area = (bounds.width * bounds.height * results.getNmPerPixel() * results.getNmPerPixel()) / 1e6;
    if (roiBounds == null) {
        return results;
    }
    // Adjust bounds relative to input results image
    final double xscale = (double) roiImageWidth / bounds.width;
    final double yscale = (double) roiImageHeight / bounds.height;
    final float minX = (float) Math.floor(roiBounds.x / xscale);
    final float maxX = (float) Math.ceil((roiBounds.x + roiBounds.width) / xscale);
    final float minY = (float) Math.floor(roiBounds.y / yscale);
    final float maxY = (float) Math.ceil((roiBounds.y + roiBounds.height) / yscale);
    // Update the area with the cropped region
    settings.area *= (maxX - minX) / bounds.width;
    settings.area *= (maxY - minY) / bounds.height;
    // Create a new set of results within the bounds
    final MemoryPeakResults newResults = new MemoryPeakResults();
    newResults.begin();
    results.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (x, y, result) -> {
        if (x >= minX && x <= maxX && y >= minY && y <= maxY) {
            newResults.add(result);
        }
    });
    newResults.end();
    newResults.copySettings(results);
    newResults.setBounds(new Rectangle((int) minX, (int) minY, (int) (maxX - minX), (int) (maxY - minY)));
    return newResults;
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) ByteProcessor(ij.process.ByteProcessor) ClusteringEngine(uk.ac.sussex.gdsc.core.clustering.ClusteringEngine) ImageProcessor(ij.process.ImageProcessor) HistogramPlotBuilder(uk.ac.sussex.gdsc.core.ij.HistogramPlot.HistogramPlotBuilder) PSFType(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFType) HelpUrls(uk.ac.sussex.gdsc.smlm.ij.plugins.HelpUrls) ResultsManager(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager) StoredDataStatistics(uk.ac.sussex.gdsc.core.utils.StoredDataStatistics) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) GoalType(org.apache.commons.math3.optim.nonlinear.scalar.GoalType) ClusteringAlgorithm(uk.ac.sussex.gdsc.core.clustering.ClusteringAlgorithm) DataException(uk.ac.sussex.gdsc.core.data.DataException) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) BinomialDiscreteInverseCumulativeProbabilityFunction(uk.ac.sussex.gdsc.core.utils.rng.BinomialDiscreteInverseCumulativeProbabilityFunction) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint) XyrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure) Collection(java.util.Collection) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) MultivariateVectorFunction(org.apache.commons.math3.analysis.MultivariateVectorFunction) ObjectiveFunction(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) PointValuePair(org.apache.commons.math3.optim.PointValuePair) NelderMeadSimplex(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex) Plot(ij.gui.Plot) CalibrationHelper(uk.ac.sussex.gdsc.smlm.data.config.CalibrationHelper) ImagePlus(ij.ImagePlus) SimplexOptimizer(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer) List(java.util.List) UniformDistribution(uk.ac.sussex.gdsc.smlm.model.UniformDistribution) ShortProcessor(ij.process.ShortProcessor) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) LeastSquaresBuilder(org.apache.commons.math3.fitting.leastsquares.LeastSquaresBuilder) TooManyEvaluationsException(org.apache.commons.math3.exception.TooManyEvaluationsException) SkewNormalFunction(uk.ac.sussex.gdsc.smlm.function.SkewNormalFunction) MultivariateFunction(org.apache.commons.math3.analysis.MultivariateFunction) MaxEval(org.apache.commons.math3.optim.MaxEval) PlugIn(ij.plugin.PlugIn) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) PrecisionResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PrecisionResultProcedure) Rectangle(java.awt.Rectangle) TraceManager(uk.ac.sussex.gdsc.smlm.results.TraceManager) Prefs(ij.Prefs) StoredData(uk.ac.sussex.gdsc.core.utils.StoredData) WindowManager(ij.WindowManager) LevenbergMarquardtOptimizer(org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) IntensityUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.IntensityUnit) ClusterPoint(uk.ac.sussex.gdsc.core.clustering.ClusterPoint) AtomicReference(java.util.concurrent.atomic.AtomicReference) MaskDistribution(uk.ac.sussex.gdsc.smlm.model.MaskDistribution) ArrayList(java.util.ArrayList) ParameterUtils(uk.ac.sussex.gdsc.smlm.ij.plugins.ParameterUtils) Trace(uk.ac.sussex.gdsc.smlm.results.Trace) GenericDialog(ij.gui.GenericDialog) InitialGuess(org.apache.commons.math3.optim.InitialGuess) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) LinkedList(java.util.LinkedList) Statistics(uk.ac.sussex.gdsc.core.utils.Statistics) DoubleData(uk.ac.sussex.gdsc.core.utils.DoubleData) StandardFluorophoreSequenceModel(uk.ac.sussex.gdsc.smlm.model.StandardFluorophoreSequenceModel) GaussianCurveFitter(org.apache.commons.math3.fitting.GaussianCurveFitter) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SimpleImageJTrackProgress(uk.ac.sussex.gdsc.core.ij.SimpleImageJTrackProgress) Calibration(ij.measure.Calibration) LeastSquaresProblem(org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem) Recorder(ij.plugin.frame.Recorder) WeightedObservedPoints(org.apache.commons.math3.fitting.WeightedObservedPoints) SamplerUtils(uk.ac.sussex.gdsc.core.utils.rng.SamplerUtils) AttributePeakResult(uk.ac.sussex.gdsc.smlm.results.AttributePeakResult) HistogramPlot(uk.ac.sussex.gdsc.core.ij.HistogramPlot) Cluster(uk.ac.sussex.gdsc.core.clustering.Cluster) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) SmlmUsageTracker(uk.ac.sussex.gdsc.smlm.ij.plugins.SmlmUsageTracker) Nullable(uk.ac.sussex.gdsc.core.annotation.Nullable) PsfHelper(uk.ac.sussex.gdsc.smlm.data.config.PsfHelper) DiagonalMatrix(org.apache.commons.math3.linear.DiagonalMatrix) InverseTransformDiscreteSampler(org.apache.commons.rng.sampling.distribution.InverseTransformDiscreteSampler) NullSource(uk.ac.sussex.gdsc.smlm.results.NullSource) Optimum(org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum) NormalizedGaussianSampler(org.apache.commons.rng.sampling.distribution.NormalizedGaussianSampler) UniformRandomProviders(uk.ac.sussex.gdsc.core.utils.rng.UniformRandomProviders) StandardResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.StandardResultProcedure) Rectangle(java.awt.Rectangle) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Example 12 with XyrResultProcedure

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

the class PulseActivationAnalysis method drawLoop.

private void drawLoop(ImagePlus imp, Roi roi, int number) {
    if (!roi.isArea()) {
        return;
    }
    // Map the ROI to a crop of the results set
    final Rectangle roiBounds = roi.getBounds();
    final Rectangle resultsBounds = results.getBounds(true);
    // @formatter:off
    final Rectangle2D.Double r = new Rectangle2D.Double(resultsBounds.width * (double) roiBounds.x / imp.getWidth(), resultsBounds.height * (double) roiBounds.y / imp.getHeight(), // Since we output pixels map the width/height to the nearest pixel
    Math.ceil(resultsBounds.width * (double) roiBounds.width / imp.getWidth()), Math.ceil(resultsBounds.height * (double) roiBounds.height / imp.getHeight()));
    // @formatter:on
    final double x = r.getX();
    final double y = r.getY();
    final int magnification = getMagnification();
    // For each result set crop out the localisation and construct an overlay
    final Overlay o = new Overlay();
    for (int i = 0; i < output.length; i++) {
        final Color color = Settings.colors[i];
        // The first result is the memory results
        final MemoryPeakResults localResults = (MemoryPeakResults) output[i].getOutput(0);
        localResults.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (xx, yy, result) -> {
            if (r.contains(xx, yy)) {
                add(o, (xx - x) * magnification, (yy - y) * magnification, color);
            }
        });
    }
    // This results in a change of shape depending on where the roi is positioned
    int width = (int) r.getWidth();
    int height = (int) r.getHeight();
    width *= magnification;
    height *= magnification;
    final ImageProcessor ip = new ByteProcessor(width, height);
    final String loopTitle = imp.getTitle() + " Loop " + number;
    imp = WindowManager.getImage(loopTitle);
    if (imp == null) {
        imp = new ImagePlus(loopTitle, ip);
        imp.show();
    } else {
        imp.setProcessor(ip);
        imp.getWindow().toFront();
    }
    imp.setOverlay(o);
}
Also used : Color(java.awt.Color) Choice(java.awt.Choice) RandomUtils(uk.ac.sussex.gdsc.core.utils.rng.RandomUtils) ByteProcessor(ij.process.ByteProcessor) Calibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.Calibration) IdPeakResult(uk.ac.sussex.gdsc.smlm.results.IdPeakResult) ImageProcessor(ij.process.ImageProcessor) Rectangle2D(java.awt.geom.Rectangle2D) ResultsImageSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSettings) ResultsSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsSettings) Future(java.util.concurrent.Future) ImageStatistics(ij.process.ImageStatistics) Pair(org.apache.commons.lang3.tuple.Pair) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Optional(com.google.common.base.Optional) ContinuousUniformSampler(org.apache.commons.rng.sampling.distribution.ContinuousUniformSampler) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) PeakResults(uk.ac.sussex.gdsc.smlm.results.PeakResults) DiscreteSampler(org.apache.commons.rng.sampling.distribution.DiscreteSampler) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) EnumSet(java.util.EnumSet) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) XyrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) PeakResultsList(uk.ac.sussex.gdsc.smlm.results.PeakResultsList) NotImplementedException(uk.ac.sussex.gdsc.core.data.NotImplementedException) DensityCounter(uk.ac.sussex.gdsc.core.clustering.DensityCounter) ResultsImageType(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageType) OffsetPointRoi(uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) Logger(java.util.logging.Logger) ConcurrencyUtils(uk.ac.sussex.gdsc.core.utils.concurrent.ConcurrencyUtils) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Plot(ij.gui.Plot) Executors(java.util.concurrent.Executors) CentroidMethod(uk.ac.sussex.gdsc.smlm.results.Cluster.CentroidMethod) CalibrationHelper(uk.ac.sussex.gdsc.smlm.data.config.CalibrationHelper) ImagePlus(ij.ImagePlus) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) SharedStateContinuousSampler(org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler) ShapeRoi(ij.gui.ShapeRoi) PlugIn(ij.plugin.PlugIn) Roi(ij.gui.Roi) CompositeImage(ij.CompositeImage) IntStream(java.util.stream.IntStream) Rectangle(java.awt.Rectangle) TraceManager(uk.ac.sussex.gdsc.smlm.results.TraceManager) Prefs(ij.Prefs) WindowManager(ij.WindowManager) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) Level(java.util.logging.Level) PointRoi(ij.gui.PointRoi) AWTEvent(java.awt.AWTEvent) Trace(uk.ac.sussex.gdsc.smlm.results.Trace) UnitSphereSampler(org.apache.commons.rng.sampling.UnitSphereSampler) Molecule(uk.ac.sussex.gdsc.core.clustering.DensityCounter.Molecule) ImagePeakResultsFactory(uk.ac.sussex.gdsc.smlm.ij.results.ImagePeakResultsFactory) GenericDialog(ij.gui.GenericDialog) Overlay(ij.gui.Overlay) ExecutorService(java.util.concurrent.ExecutorService) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) ResultsImageSizeMode(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSizeMode) Checkbox(java.awt.Checkbox) Window(java.awt.Window) SplittableUniformRandomProvider(uk.ac.sussex.gdsc.core.utils.rng.SplittableUniformRandomProvider) ResultsImageMode(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageMode) Recorder(ij.plugin.frame.Recorder) SamplerUtils(uk.ac.sussex.gdsc.core.utils.rng.SamplerUtils) ActionEvent(java.awt.event.ActionEvent) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) ImageStack(ij.ImageStack) PeakResultStoreList(uk.ac.sussex.gdsc.smlm.results.PeakResultStoreList) NormalizedGaussianSampler(org.apache.commons.rng.sampling.distribution.NormalizedGaussianSampler) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) UniformRandomProviders(uk.ac.sussex.gdsc.core.utils.rng.UniformRandomProviders) ByteProcessor(ij.process.ByteProcessor) Color(java.awt.Color) Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) ImagePlus(ij.ImagePlus) ImageProcessor(ij.process.ImageProcessor) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Overlay(ij.gui.Overlay)

Aggregations

IJ (ij.IJ)12 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)12 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)12 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)12 XyrResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure)12 PlugIn (ij.plugin.PlugIn)11 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)11 WindowManager (ij.WindowManager)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)10 ImagePlus (ij.ImagePlus)9 Rectangle (java.awt.Rectangle)9 MathUtils (uk.ac.sussex.gdsc.core.utils.MathUtils)9 InputSource (uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource)9 Plot (ij.gui.Plot)8 List (java.util.List)8 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)7 TextUtils (uk.ac.sussex.gdsc.core.utils.TextUtils)7 ImageProcessor (ij.process.ImageProcessor)6 Color (java.awt.Color)6