Search in sources :

Example 51 with TextWindow

use of ij.text.TextWindow in project GDSC-SMLM by aherbert.

the class ResultsMatchCalculator method createResultsWindow.

private static TextWindow createResultsWindow(boolean doIdAnalysis) {
    final String header = createResultsHeader(doIdAnalysis);
    final TextWindow resultsWindow = ImageJUtils.refresh(resultsWindowRef, () -> new TextWindow(TITLE + " Results", header, "", 900, 300));
    ImageJUtils.refreshHeadings(resultsWindow, header, true);
    return resultsWindow;
}
Also used : TextWindow(ij.text.TextWindow) BufferedTextWindow(uk.ac.sussex.gdsc.core.ij.BufferedTextWindow)

Example 52 with TextWindow

use of ij.text.TextWindow in project GDSC-SMLM by aherbert.

the class ClassificationMatchCalculator method runCompareClassifications.

private void runCompareClassifications(MemoryPeakResults results1, MemoryPeakResults results2) {
    final List<PointPair> allMatches = new LinkedList<>();
    // Optionally exclude results which do not have an id and/or category
    Predicate<PeakResult> test = settings.useId == ClassAnalysis.IGNORE_ZERO ? r -> r.getId() != 0 : null;
    if (settings.useCategory == ClassAnalysis.IGNORE_ZERO) {
        final Predicate<PeakResult> test2 = r -> r.getCategory() != 0;
        test = test == null ? test2 : test.and(test2);
    } else if (test == null) {
        test = r -> true;
    }
    // Divide the results into time points
    final TIntObjectHashMap<List<PeakResultPoint>> coordinates1 = getCoordinates(results1, test);
    final TIntObjectHashMap<List<PeakResultPoint>> coordinates2 = getCoordinates(results2, test);
    // Process each time point
    int n1 = 0;
    int n2 = 0;
    for (final int t : getTimepoints(coordinates1, coordinates2)) {
        final Coordinate[] c1 = getCoordinates(coordinates1, t);
        final Coordinate[] c2 = getCoordinates(coordinates2, t);
        n1 += c1.length;
        n2 += c2.length;
        final List<PointPair> matches = new LinkedList<>();
        MatchCalculator.analyseResults3D(c1, c2, settings.matchDistance, null, null, null, matches);
        allMatches.addAll(matches);
    }
    if (allMatches.isEmpty()) {
        IJ.error(TITLE, "No localisation matches between the two results sets");
        return;
    }
    // Get the unique Ids and Categories in the matches.
    final Mapper ids = getMapper(allMatches, PeakResult::getId, settings.useId);
    final Mapper cats = getMapper(allMatches, PeakResult::getCategory, settings.useCategory);
    // Map id/category to an index = stride * cat + id
    final int stride = ids.size();
    // Any integer is allowed as an index
    if ((long) stride * cats.size() > 1L << 32) {
        IJ.error(TITLE, "Too many combinations of id and category to assigne unique labels");
        return;
    }
    // Extract indices
    final int[] set1 = new int[allMatches.size()];
    final int[] set2 = new int[allMatches.size()];
    int i = 0;
    for (final PointPair r : allMatches) {
        set1[i] = toIndex(stride, ids, cats, ((PeakResultPoint) r.getPoint1()).getPeakResult());
        set2[i] = toIndex(stride, ids, cats, ((PeakResultPoint) r.getPoint2()).getPeakResult());
        i++;
    }
    final Resequencer re = new Resequencer();
    re.setCacheMap(true);
    re.renumber(set1);
    re.renumber(set2);
    // Compare
    final RandIndex r = new RandIndex().compute(set1, set2);
    final TextWindow resultsWindow = ImageJUtils.refresh(resultsWindowRef, () -> new TextWindow(TITLE + " Results", "Results1\tResults2\tID\tCategory\tn1\tc1\tn2\tc2\tMatched\tRand Index\tAdjusted RI", "", 900, 300));
    try (BufferedTextWindow bw = new BufferedTextWindow(resultsWindow)) {
        final StringBuilder sb = new StringBuilder(2048);
        sb.append(results1.getName()).append('\t');
        sb.append(results2.getName()).append('\t');
        sb.append(ANALYSIS_OPTION[settings.useId.ordinal()]).append('\t');
        sb.append(ANALYSIS_OPTION[settings.useCategory.ordinal()]).append('\t');
        sb.append(n1).append('\t');
        sb.append(MathUtils.max(set1) + 1).append('\t');
        sb.append(n2).append('\t');
        sb.append(MathUtils.max(set2) + 1).append('\t');
        sb.append(set1.length).append('\t');
        sb.append(MathUtils.rounded(r.getRandIndex())).append('\t');
        sb.append(MathUtils.rounded(r.getAdjustedRandIndex())).append('\t');
        bw.append(sb.toString());
    }
}
Also used : PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) Arrays(java.util.Arrays) ConfigurationException(uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException) Prefs(ij.Prefs) TextWindow(ij.text.TextWindow) FrameCounter(uk.ac.sussex.gdsc.smlm.results.count.FrameCounter) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConversionException(com.thoughtworks.xstream.converters.ConversionException) TIntProcedure(gnu.trove.procedure.TIntProcedure) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) LinkedList(java.util.LinkedList) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) RandIndex(uk.ac.sussex.gdsc.core.match.RandIndex) Predicate(java.util.function.Predicate) BufferedTextWindow(uk.ac.sussex.gdsc.core.ij.BufferedTextWindow) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) ToIntFunction(java.util.function.ToIntFunction) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) NamedObject(uk.ac.sussex.gdsc.smlm.data.NamedObject) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) Coordinate(uk.ac.sussex.gdsc.core.match.Coordinate) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) TIntHashSet(gnu.trove.set.hash.TIntHashSet) XyzrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyzrResultProcedure) List(java.util.List) PointPair(uk.ac.sussex.gdsc.core.match.PointPair) Resequencer(uk.ac.sussex.gdsc.core.match.Resequencer) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) MatchCalculator(uk.ac.sussex.gdsc.core.match.MatchCalculator) PlugIn(ij.plugin.PlugIn) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) BufferedTextWindow(uk.ac.sussex.gdsc.core.ij.BufferedTextWindow) Resequencer(uk.ac.sussex.gdsc.core.match.Resequencer) RandIndex(uk.ac.sussex.gdsc.core.match.RandIndex) LinkedList(java.util.LinkedList) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint) TextWindow(ij.text.TextWindow) BufferedTextWindow(uk.ac.sussex.gdsc.core.ij.BufferedTextWindow) Coordinate(uk.ac.sussex.gdsc.core.match.Coordinate) LinkedList(java.util.LinkedList) List(java.util.List) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) PointPair(uk.ac.sussex.gdsc.core.match.PointPair) PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint)

Example 53 with TextWindow

use of ij.text.TextWindow in project GDSC-SMLM by aherbert.

the class ConfigurationTemplate method showTemplateInfo.

/**
 * Show the info from the template.
 *
 * @param name the name
 */
private void showTemplateInfo(String name) {
    final TemplateSettings settings = getTemplate(name);
    if (settings == null || settings.getNotesCount() == 0) {
        return;
    }
    if (infoWindow == null || !infoWindow.isVisible()) {
        infoWindow = new TextWindow(title + " Info", "", "", 450, 250);
        // Put underneath the results window
        if (resultsWindow != null) {
            final Point p = resultsWindow.getLocation();
            p.y += resultsWindow.getHeight();
            infoWindow.setLocation(p);
        }
    }
    infoWindow.getTextPanel().clear();
    for (final String note : settings.getNotesList()) {
        // Text window cannot show tabs
        infoWindow.append(note.replace('\t', ','));
    }
}
Also used : DefaultTemplateSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.DefaultTemplateSettings) TemplateSettings(uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings) ConfigurationTemplateSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ConfigurationTemplateSettings) TextWindow(ij.text.TextWindow) Point(java.awt.Point)

Example 54 with TextWindow

use of ij.text.TextWindow in project GDSC-SMLM by aherbert.

the class ConfigurationTemplate method updateResults.

/**
 * Update the results window using the current selected slice from the template image.
 *
 * @param slice the slice
 * @return the text window
 */
public TextWindow updateResults(int slice) {
    if (slice == currentSlice || text == null) {
        return resultsWindow;
    }
    currentSlice = slice;
    if (resultsWindow == null || !resultsWindow.isVisible()) {
        resultsWindow = new TextWindow(title + " Results", headings, "", 450, 250);
        // Put next to the image
        final ImagePlus tmpImp = WindowManager.getImage(templateId);
        if (tmpImp != null && tmpImp.getWindow() != null) {
            final ImageWindow iw = tmpImp.getWindow();
            final Point p = iw.getLocation();
            p.x += iw.getWidth();
            resultsWindow.setLocation(p);
        }
    }
    resultsWindow.getTextPanel().clear();
    final String data = text.get(slice);
    if (!TextUtils.isNullOrEmpty(data)) {
        resultsWindow.append(data);
    }
    return resultsWindow;
}
Also used : ImageWindow(ij.gui.ImageWindow) TextWindow(ij.text.TextWindow) Point(java.awt.Point) ImagePlus(ij.ImagePlus)

Example 55 with TextWindow

use of ij.text.TextWindow in project GDSC-SMLM by aherbert.

the class DiffusionRateTest method msdAnalysis.

/**
 * Tabulate the observed MSD for different jump distances.
 *
 * @param points the points
 */
private void msdAnalysis(ArrayList<Point> points) {
    if (myMsdAnalysisSteps == 0) {
        return;
    }
    IJ.showStatus("MSD analysis ...");
    IJ.showProgress(1, myMsdAnalysisSteps);
    // This will only be fast if the list is an array
    final Point[] list = points.toArray(new Point[0]);
    // Compute the base MSD
    final Point origin = new Point(0, 0, 0);
    double sum = origin.distance2(list[0]);
    int count = 1;
    for (int i = 1; i < list.length; i++) {
        final Point last = list[i - 1];
        final Point current = list[i];
        if (last.id == current.id) {
            sum += last.distance2(current);
        } else {
            sum += origin.distance2(current);
        }
        count++;
    }
    // Create a new set of points that have coordinates that
    // are the rolling average over the number of aggregate steps
    final DoubleRollingArray x = new DoubleRollingArray(pluginSettings.aggregateSteps);
    final DoubleRollingArray y = new DoubleRollingArray(pluginSettings.aggregateSteps);
    int id = 0;
    int length = 0;
    for (final Point p : points) {
        if (p.id != id) {
            x.clear();
            y.clear();
        }
        id = p.id;
        x.add(p.x);
        y.add(p.y);
        // Only create a point if the full aggregation size is reached
        if (x.isFull()) {
            list[length++] = new Point(id, x.getAverage(), y.getAverage());
        }
    }
    // Q - is this useful?
    final double p = myPrecision / settings.getPixelPitch();
    final UniformRandomProvider rng = UniformRandomProviders.create();
    final NormalizedGaussianSampler gauss = SamplerUtils.createNormalizedGaussianSampler(rng);
    final int totalSteps = (int) Math.ceil(settings.getSeconds() * settings.getStepsPerSecond() - pluginSettings.aggregateSteps);
    final int limit = Math.min(totalSteps, myMsdAnalysisSteps);
    final Ticker ticker = ImageJUtils.createTicker(limit, 1);
    final TextWindow msdTable = createMsdTable((sum / count) * settings.getStepsPerSecond() / conversionFactor);
    try (BufferedTextWindow bw = new BufferedTextWindow(msdTable)) {
        bw.setIncrement(0);
        for (int step = 1; step <= myMsdAnalysisSteps; step++) {
            sum = 0;
            count = 0;
            for (int i = step; i < length; i++) {
                final Point last = list[i - step];
                final Point current = list[i];
                if (last.id == current.id) {
                    if (p == 0) {
                        sum += last.distance2(current);
                        count++;
                    } else {
                        // is the same if enough samples are present
                        for (int ii = 1; ii-- > 0; ) {
                            sum += last.distance2(current, p, gauss);
                            count++;
                        }
                    }
                }
            }
            if (count == 0) {
                break;
            }
            bw.append(addResult(step, sum, count));
            ticker.tick();
        }
    }
    IJ.showProgress(1);
}
Also used : TextWindow(ij.text.TextWindow) BufferedTextWindow(uk.ac.sussex.gdsc.core.ij.BufferedTextWindow) BufferedTextWindow(uk.ac.sussex.gdsc.core.ij.BufferedTextWindow) DoubleRollingArray(uk.ac.sussex.gdsc.core.utils.DoubleRollingArray) Ticker(uk.ac.sussex.gdsc.core.logging.Ticker) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) NormalizedGaussianSampler(org.apache.commons.rng.sampling.distribution.NormalizedGaussianSampler)

Aggregations

TextWindow (ij.text.TextWindow)61 Point (java.awt.Point)11 BufferedTextWindow (uk.ac.sussex.gdsc.core.ij.BufferedTextWindow)11 BufferedTextWindow (gdsc.core.ij.BufferedTextWindow)7 ArrayList (java.util.ArrayList)6 PointPair (uk.ac.sussex.gdsc.core.match.PointPair)5 IJ (ij.IJ)4 ImagePlus (ij.ImagePlus)4 LinkedList (java.util.LinkedList)4 Coordinate (uk.ac.sussex.gdsc.core.match.Coordinate)4 ImageROIPainter (gdsc.smlm.ij.utils.ImageROIPainter)3 List (java.util.List)3 PeakResultPoint (uk.ac.sussex.gdsc.smlm.results.PeakResultPoint)3 Coordinate (gdsc.core.match.Coordinate)2 MatchResult (gdsc.core.match.MatchResult)2 PointPair (gdsc.core.match.PointPair)2 TIntHashSet (gnu.trove.set.hash.TIntHashSet)2 GenericDialog (ij.gui.GenericDialog)2 ImageWindow (ij.gui.ImageWindow)2 PlotWindow (ij.gui.PlotWindow)2