Search in sources :

Example 6 with ResultsTable

use of ij.measure.ResultsTable in project imagej1 by imagej.

the class XYCoordinates method saveSelectionCoordinates.

private void saveSelectionCoordinates(ImagePlus imp) {
    SaveDialog sd = new SaveDialog("Save Coordinates as Text...", imp.getTitle(), ".csv");
    String name = sd.getFileName();
    if (name == null)
        return;
    String dir = sd.getDirectory();
    Roi roi = imp.getRoi();
    ImageProcessor ip = imp.getProcessor();
    ImageProcessor mask = roi.getMask();
    Rectangle r = roi.getBounds();
    ResultsTable rt = new ResultsTable();
    boolean rgb = imp.getBitDepth() == 24;
    for (int y = 0; y < r.height; y++) {
        for (int x = 0; x < r.width; x++) {
            if (mask == null || mask.getPixel(x, y) != 0) {
                rt.incrementCounter();
                rt.addValue("X", r.x + x);
                rt.addValue("Y", r.y + y);
                if (rgb) {
                    int c = ip.getPixel(r.x + x, r.y + y);
                    rt.addValue("Red", (c & 0xff0000) >> 16);
                    rt.addValue("Green", (c & 0xff00) >> 8);
                    rt.addValue("Blue", c & 0xff);
                } else
                    rt.addValue("Value", ip.getPixelValue(r.x + x, r.y + y));
            }
        }
    }
    rt.save(dir + name);
}
Also used : ResultsTable(ij.measure.ResultsTable)

Example 7 with ResultsTable

use of ij.measure.ResultsTable in project TrakEM2 by trakem2.

the class Display method getTreePathMeasureListener.

private ActionListener getTreePathMeasureListener(final Tree tree) {
    return new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent ae) {
            final String command = ae.getActionCommand();
            if (command.equals("Shortest distances between all pairs of nodes tagged as...")) {
                final TreeMap<String, Tag> sm = getTags(tree);
                if (null == sm)
                    return;
                if (1 == sm.size()) {
                    Utils.showMessage("Need at least two different tags in the tree!");
                    return;
                }
                final String[] stags = asStrings(sm);
                sm.keySet().toArray(stags);
                final GenericDialog gd = new GenericDialog("Choose tag");
                gd.addChoice("Upstream tag:", stags, stags[0]);
                gd.addChoice("Downstream tag:", stags, stags[1]);
                gd.addNumericField("Scale:", 1, 2);
                final LayerSet ls = tree.getLayerSet();
                final int resample = Display3D.estimateResamplingFactor(ls, ls.getLayerWidth(), ls.getLayerHeight());
                gd.addSlider("Resample: ", 1, Math.max(resample, 100), resample);
                gd.showDialog();
                if (gd.wasCanceled())
                    return;
                final Tag upstreamTag = sm.get(gd.getNextChoice());
                final Tag downstreamTag = sm.get(gd.getNextChoice());
                final List<Tree<?>.MeasurementPair> pairs = tree.measureTaggedPairs(upstreamTag, downstreamTag);
                ResultsTable rt = null;
                int index = 1;
                for (final Tree<?>.MeasurementPair pair : pairs) {
                    rt = pair.toResultsTable(rt, index++, 1.0, resample);
                    Utils.showProgress(((double) index) / pairs.size());
                }
                if (index > 0) {
                    rt.show(pairs.get(0).getResultsTableTitle());
                } else {
                    Utils.logAll("No pairs found for '" + upstreamTag + "' and '" + downstreamTag + "'");
                }
                return;
            }
            // Measurements related to the node under the mouse
            final Point p = getCanvas().consumeLastPopupPoint();
            final Node clicked = tree.findClosestNodeW(p.x, p.y, getLayer(), canvas.getMagnification());
            if (null == clicked) {
                final Calibration cal = getLayerSet().getCalibration();
                Utils.log("No node found at " + p.x * cal.pixelWidth + ", " + p.y * cal.pixelHeight);
                return;
            }
            ResultsTable rt = null;
            if (command.equals("Distance from this node to root")) {
                rt = tree.measurePathDistance(clicked, tree.getRoot(), null);
            } else if (command.equals("Distance from this node to the marked node")) {
                if (null == tree.getMarked()) {
                    Utils.log("No marked node!");
                    return;
                }
                rt = tree.measurePathDistance(clicked, tree.getMarked(), null);
            } else if (command.equals("Distance from this node to all nodes tagged as...")) {
                final Set<Tag> tags = tree.findTags();
                if (tags.isEmpty()) {
                    Utils.log("The nodes of the tree '" + tree + "' don't have any tags!");
                    return;
                }
                final TreeMap<String, Tag> sm = new TreeMap<String, Tag>();
                for (final Tag t : tags) sm.put(t.toString(), t);
                final String[] stags = new String[sm.size()];
                sm.keySet().toArray(stags);
                final GenericDialog gd = new GenericDialog("Choose tag");
                gd.addChoice("Tag:", stags, stags[0]);
                gd.showDialog();
                if (gd.wasCanceled())
                    return;
                // So we have a Tag:
                final Tag tag = sm.get(gd.getNextChoice());
                // Measure distance to each node that has the tag
                for (final Node nd : (Collection<Node>) tree.getRoot().getSubtreeNodes()) {
                    if (nd.hasTag(tag)) {
                        rt = tree.measurePathDistance(clicked, nd, rt);
                    }
                }
            }
            if (null == rt)
                Utils.log("No nodes found!");
            else
                rt.show("Tree path measurements");
        }
    };
}
Also used : ActionEvent(java.awt.event.ActionEvent) Point(java.awt.Point) Calibration(ij.measure.Calibration) TreeMap(java.util.TreeMap) Point(java.awt.Point) ActionListener(java.awt.event.ActionListener) GenericDialog(ij.gui.GenericDialog) Collection(java.util.Collection) ResultsTable(ij.measure.ResultsTable)

Example 8 with ResultsTable

use of ij.measure.ResultsTable in project TrakEM2 by trakem2.

the class ImageJCommandListener method commandExecuting.

// I know, I could create a hashtable and then map methods of this class to each command key ... this is just easier, and performance-wise nobody cares
// Or even a hastable with String command keys and then a number as value, and use a gigantic switch block. So much pain to write. WHAT I REALLY WANT is a switch that takes a String and is fast because it has its own hash setup.
public String commandExecuting(final String command) {
    // Utils.log2("Command: " + command);
    // 1 - check source
    ImagePlus current = WindowManager.getCurrentImage();
    // not a trakem2 display: continue happily
    if (!(current instanceof FakeImagePlus))
        return command;
    // 2 - identify project
    final FakeImagePlus fimp = (FakeImagePlus) current;
    final Display display = fimp.getDisplay();
    final LayerSet layer_set = display.getLayer().getParent();
    final Project project = display.getProject();
    final ProjectTree ptree = project.getProjectTree();
    final Displayable active = display.getActive();
    final Selection selection = display.getSelection();
    // FILE menu
    if (command.equals("Save")) {
        project.save();
        return null;
    } else // EDIT menu
    if (command.equals("Undo")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Cut")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Copy")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Copy to System")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Paste")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Clear")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Clear Outside")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Fill")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Draw")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Invert")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else // EDIT - SELECTION menu
    if (command.equals("Select All")) {
        if (ProjectToolbar.SELECT == Toolbar.getToolId()) {
            selection.selectAll();
            return null;
        }
        return command;
    } else if (command.equals("Select None")) {
        if (ProjectToolbar.SELECT == Toolbar.getToolId()) {
            display.select(null);
            return null;
        }
        return command;
    } else if (command.equals("Restore Selection")) {
        if (ProjectToolbar.SELECT == Toolbar.getToolId()) {
            selection.restore();
            return null;
        }
        return command;
    } else // IMAGE - TYPE menu
    if (command.equals("8-bit")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("16-bit")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("32-bit")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("8-bit Color")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("RGB Color")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("RGB Stack") || command.equals("HSB Stack")) {
        Utils.showMessage("Can't convert to " + command);
        return null;
    } else // IMAGE - ADJUST menu
    if (command.equals("Brightness/Contrast...")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Window/Level...")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Color Balance...")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Threshold...")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Size...")) {
        if (null != active)
            selection.specify();
        return null;
    } else if (command.equals("Canvas Size...")) {
        display.resizeCanvas();
        return null;
    } else // IMAGE menu
    if (command.equals("Show Info...")) {
        // TODO perhaps it should show only for images ...
        if (null == active) {
            ptree.showInfo(project.getRootProjectThing());
        } else {
            ProjectThing pt = project.findProjectThing(active);
            if (null != pt)
                ptree.showInfo(pt);
        }
        return null;
    } else // IMAGE - COLOR menu
    if (in(command, new String[] { "RGB Split", "RGB Merge...", "Stack to RGB", "Make Composite" })) {
        notAvailable(command);
        return null;
    } else if (command.equals("Show LUT")) {
        return setTempCurrentImage(command, active);
    } else if (command.equals("Edit LUT...")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("Average Color")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("RGB to CIELAB")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else if (command.equals("RGB to Luminance")) {
        // TODO forward to the active image, if any
        niy(command);
        return null;
    } else // IMAGE STACK menu
    if (in(command, new String[] { "Add Slice", "Delete Slice" })) {
        Utils.showMessage("Go to the Layer Tree and right-click to add/delete a layer.");
        return null;
    } else if (command.equals("Next Slice [>]")) {
        display.nextLayer(IJ.shiftKeyDown() ? Event.SHIFT_MASK : 0);
        return null;
    } else if (command.equals("Previous Slice [<]")) {
        display.previousLayer(IJ.shiftKeyDown() ? Event.SHIFT_MASK : 0);
        return null;
    } else if (in(command, new String[] { "Set Slice", "Images to Stack", "Stack to Images", "Make Montage..." })) {
        notAvailable(command);
        return null;
    } else if (command.equals("Reslice [/]...")) {
        // TODO
        niy(command);
        return null;
    } else if (command.equals("Z Project...")) {
        // TODO
        niy(command);
        return null;
    } else if (command.equals("3D Project...")) {
        // TODO
        niy(command);
        return null;
    } else if (command.equals("Plot Z-axis Profile")) {
        // TODO
        niy(command);
        return null;
    } else if (command.equals("Start Animation [\\]")) {
        // TODO
        niy(command);
        return null;
    } else if (command.equals("Stop Animation")) {
        // TODO
        niy(command);
        return null;
    } else // IMAGE menu again
    if (command.equals("Crop")) {
        notAvailable(command);
        return null;
    } else if (in(command, new String[] { "Translate...", "Scale..." })) {
        if (null != active)
            selection.specify();
        return null;
    } else if (command.equals("Duplicate...")) {
        if (null != active && active.getClass().equals(Patch.class)) {
            // TODO stacks?
            // 2.5 security factor: for awt in non-1.6.0 machines
            project.getLoader().releaseToFit((long) (project.getLoader().estimateImageFileSize((Patch) active, 0) * 2.5));
            new ImagePlus(active.getTitle(), ((Patch) active).getImageProcessor().duplicate()).show();
        }
        return null;
    } else if (command.equals("Rename...")) {
        if (null != active) {
            active.adjustProperties();
            Display.updateSelection();
        }
        return null;
    } else // IMAGE ROTATE menu
    if (command.equals("Flip Horizontally")) {
        selection.apply(2, new double[] { -1, 1 });
        return null;
    } else if (command.equals("Flip Vertically")) {
        selection.apply(2, new double[] { 1, -1 });
        return null;
    } else if (command.equals("Rotate 90 Degrees Right")) {
        selection.apply(1, new double[] { 90 });
        return null;
    } else if (command.equals("Rotate 90 Degrees Left")) {
        selection.apply(1, new double[] { -90 });
        return null;
    } else if (command.equals("Arbitrarily...")) {
        if (null != active)
            selection.specify();
        return null;
    } else // IMAGE ZOOM menu
    if (command.equals("To Selection")) {
        Roi roi = fimp.getRoi();
        if (null != roi) {
            Rectangle b = roi.getBounds();
            b.x -= b.width / 2;
            b.y -= b.height / 2;
            b.width *= 2;
            b.height *= 2;
            display.getCanvas().showCentered(b);
        }
        return null;
    } else if (command.equals("View 100%")) {
        // TODO
        niy(command);
        return null;
    } else // ANALYZE menu
    if (command.equals("Measure")) {
        // Minimal measurement: area of closed ROIs, length of unclosed ROIs, calibrated.
        Roi roi = fimp.getRoi();
        if (null != roi) {
            Calibration cal = fimp.getCalibration();
            AffineTransform caff = new AffineTransform();
            caff.scale(cal.pixelWidth, cal.pixelHeight);
            if (M.isAreaROI(roi)) {
                Area area = M.getArea(roi);
                area = area.createTransformedArea(caff);
                ResultsTable rt = Utils.createResultsTable("ROI area", new String[] { "area", "perimeter" });
                rt.incrementCounter();
                rt.addLabel("units", cal.getUnit());
                rt.addValue(0, Math.abs(AreaCalculations.area(area.getPathIterator(null))));
                rt.addValue(1, roi.getLength());
                rt.show("ROI area");
            } else {
                ResultsTable rt = Utils.createResultsTable("ROI length", new String[] { "length" });
                rt.incrementCounter();
                rt.addLabel("units", cal.getUnit());
                rt.addValue(0, roi.getLength());
                rt.show("ROI length");
            }
            return null;
        } else if (null != active) {
            // Measure the active displayable
            if (active.getClass() == Patch.class) {
                // measure like 'm' would in ImageJ for an image
                ImagePlus imp = ((Patch) active).getImagePlus();
                imp.setCalibration(active.getLayer().getParent().getCalibrationCopy());
                IJ.run(imp, "Measure", "");
            } else {
                // Call measure like ProjectThing does
                ProjectThing pt = active.getProject().findProjectThing(active);
                if (active instanceof Profile)
                    ((ProjectThing) pt.getParent()).measure();
                else
                    pt.measure();
            }
            return null;
        }
        Utils.log("Draw a ROI or select an object!");
        return null;
    } else if (in(command, new String[] { "Analyze Particles...", "Histogram", "Plot Profile", "Surface Plot...", "Color Inspector 3D", "3D Surface Plot", "Color Histogram" })) {
        return setTempCurrentImage(command, active);
    } else if (command.equals("Label")) {
        notAvailable(command);
        return null;
    } else // PLUGINS menu
    if (command.equals("Volume Viewer")) {
        return runOnVirtualLayerSet(command, layer_set, display);
    } else if (command.equals("3D Viewer")) {
        // it's virtual and non-caching, will appear as a regular ImageJ stack
        layer_set.createLayerStack(Displayable.class, ImagePlus.COLOR_RGB, display.getDisplayChannelAlphas()).getImagePlus().show();
        return command;
    } else // PROCESS menu and submenus
    if (in(command, new String[] { "FFT", "Fast FFT (2D/3D)" })) {
        return setTempCurrentImage(command, active);
    } else if (in(command, new String[] { "Bandpass Filter...", "Custom Filter...", "FD Math...", "Swap Quadrants", "Convolve...", "Gaussian Blur...", "Median...", "Mean...", "Minimum...", "Maximum...", "Unsharp Mask...", "Variance...", "Show Circular Masks...", "Subtract Background..." })) {
        return duplicate(command, active);
    } else if (in(command, new String[] { "Smooth", "Sharpen", "Find Edges", "Enhance Contrast", "Add Noise", "Add Specified Noise...", "Salt and Pepper", "Despeckle", "Remove Outliers...", "North", "Northeast", "East", "Southeast", "South", "Southwest", "West", "Northwest", "Make Binary", "Convert to Mask", "Find Maxima...", "Erode", "Dilate", "Open ", "Close-", "Outline", "Fill Holes", "Skeletonize", "Distance Map", "Ultimate Points", "Watershed", "Add...", "Subtract...", "Multiply...", "Divide...", "AND...", "OR...", "XOR...", "Min...", "Max...", "Gamma...", "Log", "Exp", "Square", "Square Root", "Reciprocal", "NaN Background", "Abs" })) {
        return duplicate(command, active);
    }
    /*else {
			// continue happily
			//Utils.log2("Skipping " + command);
		}*/
    // If it's part of "Save As", ignore it
    Menu menu = Menus.getSaveAsMenu();
    for (int i = menu.getItemCount() - 1; i > -1; i--) {
        if (command.equals(menu.getItem(i).getActionCommand())) {
            notAvailable(command);
            return null;
        }
    }
    // Give it back to ImageJ
    return command;
}
Also used : Rectangle(java.awt.Rectangle) Calibration(ij.measure.Calibration) ImagePlus(ij.ImagePlus) Roi(ij.gui.Roi) Project(ini.trakem2.Project) Area(java.awt.geom.Area) ProjectTree(ini.trakem2.tree.ProjectTree) AffineTransform(java.awt.geom.AffineTransform) ResultsTable(ij.measure.ResultsTable) Menu(java.awt.Menu) ProjectThing(ini.trakem2.tree.ProjectThing)

Example 9 with ResultsTable

use of ij.measure.ResultsTable in project TrakEM2 by trakem2.

the class ProjectThing method measure.

/**
 * Call on children things, and on itself if it contains a basic data type directly.
 *  All children of the same type report to the same table.
 *  Result tables are returned without ever displaying them.
 */
public HashMap<Class<?>, ResultsTable> measure(HashMap<Class<?>, ResultsTable> ht) {
    if (null == ht)
        ht = new HashMap<Class<?>, ResultsTable>();
    if (null != object && object instanceof Displayable) {
        Displayable d = (Displayable) object;
        if (d.isVisible()) {
            ResultsTable rt = d.measure(ht.get(d.getClass()));
            if (null != rt)
                ht.put(d.getClass(), rt);
            // Areas:
            if (object instanceof AreaContainer) {
                ResultsTable rta = ((AreaContainer) object).measureAreas(ht.get(AreaContainer.class));
                if (null != rta)
                    ht.put(AreaContainer.class, rta);
            }
        } else {
            Utils.log("Measure: skipping hidden object " + d.getProject().getMeaningfulTitle(d));
        }
    }
    if (null == al_children)
        return ht;
    // profile list: always special ...
    if (template.getType().equals("profile_list") && null != al_children) {
        synchronized (al_children) {
            if (al_children.size() > 1) {
                Profile[] p = new Profile[al_children.size()];
                for (int i = 0; i < al_children.size(); i++) p[i] = (Profile) al_children.get(i).object;
                ResultsTable rt = Profile.measure(p, ht.get(Profile.class), this.id);
                if (null != rt)
                    ht.put(Profile_List.class, rt);
            // return ht; // don't return: do each profile separately as well
            }
        }
    }
    synchronized (al_children) {
        for (ProjectThing child : al_children) child.measure(ht);
    }
    return ht;
}
Also used : ZDisplayable(ini.trakem2.display.ZDisplayable) Displayable(ini.trakem2.display.Displayable) HashMap(java.util.HashMap) AreaContainer(ini.trakem2.display.AreaContainer) ResultsTable(ij.measure.ResultsTable) Profile(ini.trakem2.display.Profile)

Example 10 with ResultsTable

use of ij.measure.ResultsTable in project mcib3d-core by mcib3d.

the class Objects3DPopulationInteractions method getResultsTableInteractions.

public ResultsTable getResultsTableInteractions(boolean useValueObject) {
    if (needToComputeInteractions)
        computeInteractions();
    IJ.log("Interactions completed, building results table");
    ResultsTable rt = ResultsTable.getResultsTable();
    if (rt == null)
        rt = new ResultsTable();
    rt.reset();
    for (int ia = 0; ia < population.getNbObjects(); ia++) {
        Object3D object1 = population.getObject(ia);
        rt.incrementCounter();
        if (!useValueObject) {
            rt.setLabel("A" + ia, ia);
        } else {
            rt.setLabel("A" + object1.getValue(), ia);
        }
        ArrayList<PairColocalisation> list1 = getObject1ColocalisationPairs(object1);
        ArrayList<PairColocalisation> list2 = getObject2ColocalisationPairs(object1);
        if ((list1.size() == 0) && (list2.size() == 0)) {
            if (!useValueObject)
                rt.setValue("O1", ia, 0);
            else
                rt.setValue("O1", ia, 0);
            rt.setValue("V1", ia, 0);
        }
        for (int c = 0; c < list1.size(); c++) {
            PairColocalisation colocalisation = list1.get(c);
            if (colocalisation.getObject3D1() != object1)
                IJ.log("Pb colocalisation " + object1);
            Object3D object2 = colocalisation.getObject3D2();
            int i2 = population.getIndexOf(object2);
            if (!useValueObject)
                rt.setValue("O" + (c + 1), ia, i2);
            else
                rt.setValue("O" + (c + 1), ia, object2.getValue());
            rt.setValue("V" + (c + 1), ia, colocalisation.getVolumeColoc());
        }
        int offset = list1.size();
        for (int c = 0; c < list2.size(); c++) {
            PairColocalisation colocalisation = list2.get(c);
            if (colocalisation.getObject3D1() != object1)
                IJ.log("Pb colocalisation " + object1);
            Object3D object2 = colocalisation.getObject3D2();
            int i2 = population.getIndexOf(object2);
            if (!useValueObject)
                rt.setValue("O" + (offset + c + 1), ia, i2);
            else
                rt.setValue("O" + (offset + c + 1), ia, object2.getValue());
            rt.setValue("V" + (offset + c + 1), ia, colocalisation.getVolumeColoc());
        }
    }
    return rt;
}
Also used : ResultsTable(ij.measure.ResultsTable)

Aggregations

ResultsTable (ij.measure.ResultsTable)22 HashMap (java.util.HashMap)3 Calibration (ij.measure.Calibration)2 Object3D (mcib3d.geom.Object3D)2 ImagePlus (ij.ImagePlus)1 GenericDialog (ij.gui.GenericDialog)1 Roi (ij.gui.Roi)1 Analyzer (ij.plugin.filter.Analyzer)1 TextWindow (ij.text.TextWindow)1 Project (ini.trakem2.Project)1 AreaContainer (ini.trakem2.display.AreaContainer)1 Displayable (ini.trakem2.display.Displayable)1 Profile (ini.trakem2.display.Profile)1 ZDisplayable (ini.trakem2.display.ZDisplayable)1 ProjectThing (ini.trakem2.tree.ProjectThing)1 ProjectTree (ini.trakem2.tree.ProjectTree)1 Menu (java.awt.Menu)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 ActionEvent (java.awt.event.ActionEvent)1