Search in sources :

Example 1 with Analyzer

use of ij.plugin.filter.Analyzer in project imagej1 by imagej.

the class ParticleAnalyzer method analyze.

/**
 * Performs particle analysis on the specified ImagePlus and
 *		ImageProcessor. Returns false if there is an error.
 */
public boolean analyze(ImagePlus imp, ImageProcessor ip) {
    if (this.imp == null)
        this.imp = imp;
    showResults = (options & SHOW_RESULTS) != 0;
    excludeEdgeParticles = (options & EXCLUDE_EDGE_PARTICLES) != 0;
    resetCounter = (options & CLEAR_WORKSHEET) != 0;
    showProgress = (options & SHOW_PROGRESS) != 0;
    floodFill = (options & INCLUDE_HOLES) == 0;
    recordStarts = (options & RECORD_STARTS) != 0;
    addToManager = (options & ADD_TO_MANAGER) != 0;
    if (staticRoiManager != null) {
        addToManager = true;
        roiManager = staticRoiManager;
        staticRoiManager = null;
    }
    hyperstack = imp.isHyperStack();
    if (staticResultsTable != null) {
        rt = staticResultsTable;
        staticResultsTable = null;
        showResultsWindow = false;
    }
    displaySummary = (options & DISPLAY_SUMMARY) != 0 || (options & SHOW_SUMMARY) != 0;
    inSituShow = (options & IN_SITU_SHOW) != 0;
    outputImage = null;
    ip.snapshot();
    ip.setProgressBar(null);
    if (Analyzer.isRedirectImage()) {
        redirectImp = Analyzer.getRedirectImage(imp);
        if (redirectImp == null)
            return false;
        int depth = redirectImp.getStackSize();
        if (depth > 1 && depth == imp.getStackSize()) {
            ImageStack redirectStack = redirectImp.getStack();
            redirectIP = redirectStack.getProcessor(imp.getCurrentSlice());
        } else
            redirectIP = redirectImp.getProcessor();
    } else if (imp.getType() == ImagePlus.COLOR_RGB) {
        ImagePlus original = (ImagePlus) imp.getProperty("OriginalImage");
        if (original != null && original.getWidth() == imp.getWidth() && original.getHeight() == imp.getHeight()) {
            redirectImp = original;
            redirectIP = original.getProcessor();
        }
    }
    if (!setThresholdLevels(imp, ip))
        return false;
    width = ip.getWidth();
    height = ip.getHeight();
    if (!(showChoice == NOTHING || showChoice == OVERLAY_OUTLINES || showChoice == OVERLAY_MASKS)) {
        blackBackground = Prefs.blackBackground && inSituShow;
        if (slice == 1)
            outlines = new ImageStack(width, height);
        if (showChoice == ROI_MASKS)
            drawIP = new ShortProcessor(width, height);
        else
            drawIP = new ByteProcessor(width, height);
        drawIP.setLineWidth(lineWidth);
        if (showChoice == ROI_MASKS) // Place holder for now...
        {
        } else if (showChoice == MASKS && !blackBackground)
            drawIP.invertLut();
        else if (showChoice == OUTLINES) {
            if (!inSituShow) {
                if (customLut == null)
                    makeCustomLut();
                drawIP.setColorModel(customLut);
            }
            drawIP.setFont(new Font("SansSerif", Font.PLAIN, fontSize));
            if (fontSize > 12 && inSituShow)
                drawIP.setAntialiasedText(true);
        }
        outlines.addSlice(null, drawIP);
        if (showChoice == ROI_MASKS || blackBackground) {
            drawIP.setColor(Color.black);
            drawIP.fill();
            drawIP.setColor(Color.white);
        } else {
            drawIP.setColor(Color.white);
            drawIP.fill();
            drawIP.setColor(Color.black);
        }
    }
    calibration = redirectImp != null ? redirectImp.getCalibration() : imp.getCalibration();
    if (measurements == 0)
        measurements = Analyzer.getMeasurements();
    // ignore "Limit to Threshold"
    measurements &= ~LIMIT;
    if (rt == null) {
        Frame table = WindowManager.getFrame("Results");
        if (!showResults && table != null) {
            rt = new ResultsTable();
            if (resetCounter && table instanceof TextWindow) {
                IJ.run("Clear Results");
                ((TextWindow) table).close();
                rt = Analyzer.getResultsTable();
            }
        } else
            rt = Analyzer.getResultsTable();
    }
    analyzer = new Analyzer(imp, measurements, rt);
    if (resetCounter && slice == 1 && rt.getCounter() > 0) {
        if (!Analyzer.resetCounter())
            return false;
    }
    beginningCount = Analyzer.getCounter();
    byte[] pixels = null;
    if (ip instanceof ByteProcessor)
        pixels = (byte[]) ip.getPixels();
    if (r == null) {
        r = ip.getRoi();
        mask = ip.getMask();
        if (displaySummary) {
            if (mask != null)
                totalArea = ImageStatistics.getStatistics(ip, AREA, calibration).area;
            else
                totalArea = r.width * calibration.pixelWidth * r.height * calibration.pixelHeight;
        }
    }
    minX = r.x;
    maxX = r.x + r.width;
    minY = r.y;
    maxY = r.y + r.height;
    if (r.width < width || r.height < height || mask != null) {
        if (!eraseOutsideRoi(ip, r, mask))
            return false;
    }
    int offset;
    double value;
    int inc = Math.max(r.height / 25, 1);
    int mi = 0;
    ImageWindow win = imp.getWindow();
    if (win != null)
        win.running = true;
    if (showChoice == ELLIPSES)
        measurements |= ELLIPSE;
    roiNeedsImage = (measurements & PERIMETER) != 0 || (measurements & SHAPE_DESCRIPTORS) != 0 || (measurements & FERET) != 0;
    particleCount = 0;
    wand = new Wand(ip);
    pf = new PolygonFiller();
    if (floodFill) {
        ImageProcessor ipf = ip.duplicate();
        ipf.setValue(fillColor);
        ff = new FloodFiller(ipf);
    }
    roiType = Wand.allPoints() ? Roi.FREEROI : Roi.TRACED_ROI;
    boolean done = false;
    for (int y = r.y; y < (r.y + r.height); y++) {
        offset = y * width;
        for (int x = r.x; x < (r.x + r.width); x++) {
            if (pixels != null)
                value = pixels[offset + x] & 255;
            else if (imageType == SHORT)
                value = ip.getPixel(x, y);
            else
                value = ip.getPixelValue(x, y);
            if (value >= level1 && value <= level2 && !done) {
                analyzeParticle(x, y, imp, ip);
                done = level1 == 0.0 && level2 == 255.0 && imp.getBitDepth() == 8;
            }
        }
        if (showProgress && ((y % inc) == 0))
            IJ.showProgress((double) (y - r.y) / r.height);
        if (win != null)
            canceled = !win.running;
        if (canceled) {
            Macro.abort();
            break;
        }
    }
    if (showProgress)
        IJ.showProgress(1.0);
    if (showResults && showResultsWindow && rt.getCounter() > 0)
        rt.updateResults();
    imp.deleteRoi();
    ip.resetRoi();
    ip.reset();
    if (displaySummary && IJ.getInstance() != null)
        updateSliceSummary();
    if (addToManager && roiManager != null)
        roiManager.setEditMode(imp, true);
    maxParticleCount = (particleCount > maxParticleCount) ? particleCount : maxParticleCount;
    totalCount += particleCount;
    if (!canceled)
        showResults();
    return true;
}
Also used : Analyzer(ij.plugin.filter.Analyzer)

Example 2 with Analyzer

use of ij.plugin.filter.Analyzer in project imagej1 by imagej.

the class ZAxisProfiler method getZAxisProfile.

private float[] getZAxisProfile(Roi roi, double minThreshold, double maxThreshold) {
    ImageStack stack = imp.getStack();
    if (firstTime) {
        int slices = imp.getNSlices();
        int frames = imp.getNFrames();
        timeProfile = slices == 1 && frames > 1;
    }
    int size = stack.getSize();
    boolean showProgress = size > 400 || stack.isVirtual();
    float[] values = new float[size];
    Calibration cal = imp.getCalibration();
    ResultsTable rt = new ResultsTable();
    Analyzer analyzer = new Analyzer(imp, rt);
    int measurements = Analyzer.getMeasurements();
    boolean showResults = !isPlotMaker && measurements != 0 && measurements != LIMIT;
    boolean showingLabels = firstTime && showResults && ((measurements & LABELS) != 0 || (measurements & SLICE) != 0);
    measurements |= MEAN;
    if (showResults) {
        if (!Analyzer.resetCounter())
            return null;
    }
    boolean isLine = roi != null && roi.isLine();
    int current = imp.getCurrentSlice();
    for (int i = 1; i <= size; i++) {
        if (showProgress)
            IJ.showProgress(i, size);
        if (showingLabels)
            imp.setSlice(i);
        ImageProcessor ip = stack.getProcessor(i);
        if (minThreshold != ImageProcessor.NO_THRESHOLD)
            ip.setThreshold(minThreshold, maxThreshold, ImageProcessor.NO_LUT_UPDATE);
        ip.setRoi(roi);
        ImageStatistics stats = null;
        if (isLine)
            stats = getLineStatistics(roi, ip, measurements, cal);
        else
            stats = ImageStatistics.getStatistics(ip, measurements, cal);
        analyzer.saveResults(stats, roi);
        values[i - 1] = (float) stats.mean;
    }
    if (showResults)
        rt.show("Results");
    if (showingLabels)
        imp.setSlice(current);
    return values;
}
Also used : Analyzer(ij.plugin.filter.Analyzer)

Example 3 with Analyzer

use of ij.plugin.filter.Analyzer in project imagej1 by imagej.

the class ZAxisProfiler method getHyperstackProfile.

private float[] getHyperstackProfile(Roi roi, double minThreshold, double maxThreshold) {
    int slices = imp.getNSlices();
    int frames = imp.getNFrames();
    int c = imp.getC();
    int z = imp.getZ();
    int t = imp.getT();
    int size = slices;
    if (firstTime)
        timeProfile = slices == 1 && frames > 1;
    if (options == null && slices > 1 && frames > 1 && (!isPlotMaker || firstTime)) {
        showingDialog = true;
        GenericDialog gd = new GenericDialog("Profiler");
        gd.addChoice("Profile", choices, choice);
        gd.showDialog();
        if (gd.wasCanceled())
            return null;
        choice = gd.getNextChoice();
        timeProfile = choice.equals(choices[0]);
    }
    if (options != null)
        timeProfile = frames > 1 && !options.contains("z");
    if (timeProfile)
        size = frames;
    else
        size = slices;
    float[] values = new float[size];
    Calibration cal = imp.getCalibration();
    ResultsTable rt = new ResultsTable();
    Analyzer analyzer = new Analyzer(imp, rt);
    int measurements = Analyzer.getMeasurements();
    boolean showResults = !isPlotMaker && measurements != 0 && measurements != LIMIT;
    measurements |= MEAN;
    if (showResults) {
        if (!Analyzer.resetCounter())
            return null;
    }
    ImageStack stack = imp.getStack();
    boolean showProgress = size > 400 || stack.isVirtual();
    for (int i = 1; i <= size; i++) {
        if (showProgress)
            IJ.showProgress(i, size);
        int index = 1;
        if (timeProfile)
            index = imp.getStackIndex(c, z, i);
        else
            index = imp.getStackIndex(c, i, t);
        ImageProcessor ip = stack.getProcessor(index);
        if (minThreshold != ImageProcessor.NO_THRESHOLD)
            ip.setThreshold(minThreshold, maxThreshold, ImageProcessor.NO_LUT_UPDATE);
        ip.setRoi(roi);
        ImageStatistics stats = ImageStatistics.getStatistics(ip, measurements, cal);
        analyzer.saveResults(stats, roi);
        values[i - 1] = (float) stats.mean;
    }
    if (showResults)
        rt.show("Results");
    return values;
}
Also used : Analyzer(ij.plugin.filter.Analyzer)

Example 4 with Analyzer

use of ij.plugin.filter.Analyzer in project imagej1 by imagej.

the class ResultsTable method update.

public void update(int measurements, ImagePlus imp, Roi roi) {
    if (roi == null && imp != null)
        roi = imp.getRoi();
    ResultsTable rt2 = new ResultsTable();
    Analyzer analyzer = new Analyzer(imp, measurements, rt2);
    ImageProcessor ip = new ByteProcessor(1, 1);
    ImageStatistics stats = new ByteStatistics(ip, measurements, null);
    analyzer.saveResults(stats, roi);
    // IJ.log(rt2.getColumnHeadings());
    int last = rt2.getLastColumn();
    // IJ.log("update1: "+last+"  "+getMaxColumns());
    while (last + 1 >= getMaxColumns()) {
        addColumns();
    // IJ.log("addColumns: "+getMaxColumns());
    }
    if (last < getLastColumn()) {
        last = getLastColumn();
        if (last >= rt2.getMaxColumns())
            last = rt2.getMaxColumns() - 1;
    }
    for (int i = 0; i <= last; i++) {
        // IJ.log(i+"  "+rt2.getColumn(i)+"  "+columns[i]+"  "+rt2.getColumnHeading(i)+"  "+getColumnHeading(i));
        if (rt2.getColumn(i) != null && columns[i] == null) {
            columns[i] = new double[maxRows];
            if (NaNEmptyCells)
                Arrays.fill(columns[i], Double.NaN);
            headings[i] = rt2.getColumnHeading(i);
            if (i > lastColumn)
                lastColumn = i;
        } else if (rt2.getColumn(i) == null && columns[i] != null && !keep[i])
            columns[i] = null;
    }
    if (rt2.getRowLabels() == null)
        rowLabels = null;
    else if (rt2.getRowLabels() != null && rowLabels == null) {
        rowLabels = new String[maxRows];
        rowLabelHeading = "Label";
    }
    if (size() > 0)
        show("Results");
}
Also used : Analyzer(ij.plugin.filter.Analyzer)

Example 5 with Analyzer

use of ij.plugin.filter.Analyzer in project imagej1 by imagej.

the class Overlay method measure.

/**
 * Measures the ROIs in this overlay on the specified image
 * and returns the results as a ResultsTable.
 */
public ResultsTable measure(ImagePlus imp) {
    ResultsTable rt = new ResultsTable();
    for (int i = 0; i < size(); i++) {
        Roi roi = get(i);
        imp.setRoi(roi);
        Analyzer analyzer = new Analyzer(imp, rt);
        analyzer.measure();
    }
    imp.deleteRoi();
    return rt;
}
Also used : ResultsTable(ij.measure.ResultsTable) Analyzer(ij.plugin.filter.Analyzer)

Aggregations

Analyzer (ij.plugin.filter.Analyzer)5 ResultsTable (ij.measure.ResultsTable)1