Search in sources :

Example 1 with ThresholdToSelection

use of ij.plugin.filter.ThresholdToSelection in project mcib3d-core by mcib3d.

the class Object3DFuzzy method createRoi.

@Override
public Roi createRoi(int z) {
    // IJ.write("create roi " + z);
    int sx = this.getXmax() - this.getXmin() + 1;
    int sy = this.getYmax() - this.getYmin() + 1;
    ByteProcessor mask = new ByteProcessor(sx, sy);
    // object black on white
    // mask.invert();
    draw(mask, z, 255);
    ImagePlus maskPlus = new ImagePlus("mask " + z, mask);
    // maskPlus.show();
    // IJ.run("Create Selection");
    ThresholdToSelection tts = new ThresholdToSelection();
    tts.setup("", maskPlus);
    tts.run(mask);
    maskPlus.updateAndDraw();
    // IJ.write("sel=" + maskPlus.getRoi());
    // maskPlus.hide();
    Roi roi = maskPlus.getRoi();
    Rectangle rect = roi.getBounds();
    rect.x += this.getXmin();
    rect.y += this.getYmin();
    return roi;
}
Also used : ByteProcessor(ij.process.ByteProcessor) Rectangle(java.awt.Rectangle) ThresholdToSelection(ij.plugin.filter.ThresholdToSelection) ImagePlus(ij.ImagePlus) Roi(ij.gui.Roi)

Example 2 with ThresholdToSelection

use of ij.plugin.filter.ThresholdToSelection in project mcib3d-core by mcib3d.

the class Object3DLabel method createRoi.

/**
 * Constructor for the createRoi object
 *
 * @param z Description of the Parameter
 * @return Description of the Return Value
 */
@Deprecated
public Roi createRoi(int z) {
    // IJ.write("create roi " + z);
    int sx = labelImage.sizeX;
    int sy = labelImage.sizeY;
    ByteProcessor mask = new ByteProcessor(sx, sy);
    // object black on white
    // mask.invert();
    draw(mask, z, 255);
    ImagePlus maskPlus = new ImagePlus("mask " + z, mask);
    // maskPlus.show();
    // IJ.run("Create Selection");
    ThresholdToSelection tts = new ThresholdToSelection();
    tts.setup("", maskPlus);
    tts.run(mask);
    maskPlus.updateAndDraw();
    return maskPlus.getRoi();
}
Also used : ByteProcessor(ij.process.ByteProcessor) ThresholdToSelection(ij.plugin.filter.ThresholdToSelection) ImagePlus(ij.ImagePlus)

Example 3 with ThresholdToSelection

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

the class RoiEnlarger method shrink.

private static Roi shrink(Roi roi, int n) {
    Rectangle bounds = roi.getBounds();
    int width = bounds.width + 2;
    int height = bounds.height + 2;
    ImageProcessor ip = new ByteProcessor(width, height);
    roi.setLocation(1, 1);
    ip.setColor(255);
    ip.fill(roi);
    roi.setLocation(bounds.x, bounds.y);
    boolean bb = Prefs.blackBackground;
    Prefs.blackBackground = true;
    new EDM().toEDM(ip);
    Prefs.blackBackground = bb;
    ip.setThreshold(n + 1, 255, ImageProcessor.NO_LUT_UPDATE);
    Roi roi2 = (new ThresholdToSelection()).convert(ip);
    if (roi2 == null)
        return roi;
    Rectangle bounds2 = roi2.getBounds();
    if (bounds2.width <= 0 && bounds2.height <= 0)
        return roi;
    roi2.setLocation(bounds.x + bounds2.x - 1, bounds.y + bounds2.y - 1);
    return roi2;
}
Also used : ThresholdToSelection(ij.plugin.filter.ThresholdToSelection) EDM(ij.plugin.filter.EDM)

Example 4 with ThresholdToSelection

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

the class RoiEnlarger method enlarge.

public static Roi enlarge(Roi roi, double pixels) {
    if (pixels == 0)
        return roi;
    int type = roi.getType();
    int n = (int) Math.round(pixels);
    if (type == Roi.RECTANGLE || type == Roi.OVAL)
        return enlargeRectOrOval(roi, n);
    if (n > 255)
        n = 255;
    if (n < 0)
        return shrink(roi, -n);
    Rectangle bounds = roi.getBounds();
    int width = bounds.width;
    int height = bounds.height;
    width += 2 * n + 2;
    height += 2 * n + 2;
    ImageProcessor ip = new ByteProcessor(width, height);
    ip.invert();
    roi.setLocation(n + 1, n + 1);
    ip.setColor(0);
    ip.fill(roi);
    roi.setLocation(bounds.x, bounds.y);
    boolean bb = Prefs.blackBackground;
    Prefs.blackBackground = true;
    new EDM().toEDM(ip);
    // new ImagePlus("ip", ip).show();
    Prefs.blackBackground = bb;
    ip.setThreshold(0, n, ImageProcessor.NO_LUT_UPDATE);
    Roi roi2 = (new ThresholdToSelection()).convert(ip);
    if (roi2 == null)
        return roi;
    roi2.setLocation(bounds.x - n, bounds.y - n);
    roi2.setStrokeColor(roi.getStrokeColor());
    if (roi.getStroke() != null)
        roi2.setStroke(roi.getStroke());
    return roi2;
}
Also used : ThresholdToSelection(ij.plugin.filter.ThresholdToSelection) EDM(ij.plugin.filter.EDM)

Example 5 with ThresholdToSelection

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

the class RoiInterpolator method run.

public void run(String arg) {
    RoiManager roiman = RoiManager.getInstance();
    if (roiman == null || roiman.getCount() < 2) {
        IJ.error("RoiInterpolator", "Please populate the ROI Manager with at least two ROIs");
        return;
    }
    Roi[] rois = roiman.getRoisAsArray();
    int xmax = 0;
    int xmin = Integer.MAX_VALUE;
    int ymax = 0;
    int ymin = Integer.MAX_VALUE;
    int zmax = 1;
    int zmin = Integer.MAX_VALUE;
    ArrayList<Integer> templateSlices = new ArrayList<Integer>();
    for (Roi roi : rois) {
        int slice = roiman.getSliceNumber(roi.getName());
        if (!templateSlices.contains(new Integer(slice)))
            templateSlices.add(new Integer(slice));
        if (// ignore non-slice associated ROIs
        slice == 0)
            continue;
        zmin = Math.min(slice, zmin);
        zmax = Math.max(slice, zmax);
        Rectangle bounds = roi.getBounds();
        xmin = Math.min(xmin, bounds.x);
        ymin = Math.min(ymin, bounds.y);
        xmax = Math.max(xmax, bounds.x + bounds.width);
        ymax = Math.max(ymax, bounds.y + bounds.height);
    }
    if (templateSlices.size() < 2) {
        IJ.error("RoiInterpolator", "ROIs are all on the same slice, nothing to interpolate");
        return;
    }
    // create the binary stack
    final int stackW = xmax - xmin + 1;
    final int stackH = ymax - ymin + 1;
    final int nSlices = zmax - zmin + 1;
    ImageStack stack = new ImageStack(stackW, stackH);
    for (int s = 0; s < nSlices; s++) {
        ByteProcessor bp = new ByteProcessor(stackW, stackH);
        bp.setColor(255);
        for (Roi roi : rois) {
            int slice = roiman.getSliceNumber(roi.getName());
            if (slice == zmin + s) {
                Rectangle bounds = roi.getBounds();
                roi.setLocation(bounds.x - xmin, bounds.y - ymin);
                bp.setRoi(roi);
                if (roi.getType() == Roi.RECTANGLE)
                    bp.fill();
                else
                    bp.fill(roi);
            }
        }
        stack.addSlice("" + s, bp);
    }
    // do the binary interpolation
    BinaryInterpolator bi = new BinaryInterpolator();
    bi.run(stack);
    ImagePlus binary = new ImagePlus("interpolated", stack);
    // get the ROIs
    ThresholdToSelection ts = new ThresholdToSelection();
    ts.setup("", binary);
    for (int s = 0; s < nSlices; s++) {
        if (templateSlices.contains(new Integer(s + zmin)))
            continue;
        ImageProcessor bp = stack.getProcessor(s + 1);
        int threshold = 255;
        bp.setThreshold(threshold, threshold, ImageProcessor.NO_LUT_UPDATE);
        Roi roi = ts.convert(bp);
        roi.setPosition(s + zmin);
        Rectangle bounds = roi.getBounds();
        roi.setLocation(bounds.x + xmin, bounds.y + ymin);
        roiman.addRoi(roi);
    }
    for (Roi roi : rois) {
        Rectangle bounds = roi.getBounds();
        roi.setLocation(bounds.x + xmin, bounds.y + ymin);
    }
    roiman.runCommand("sort");
    IJ.showStatus("ROIs interpolated");
}
Also used : ImageStack(ij.ImageStack) ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) Roi(ij.gui.Roi) ImagePlus(ij.ImagePlus) RoiManager(ij.plugin.frame.RoiManager) ThresholdToSelection(ij.plugin.filter.ThresholdToSelection)

Aggregations

ThresholdToSelection (ij.plugin.filter.ThresholdToSelection)10 ImagePlus (ij.ImagePlus)8 Roi (ij.gui.Roi)6 ByteProcessor (ij.process.ByteProcessor)4 Rectangle (java.awt.Rectangle)4 ImageStack (ij.ImageStack)2 EDM (ij.plugin.filter.EDM)2 ImageProcessor (ij.process.ImageProcessor)2 AffineTransform (java.awt.geom.AffineTransform)2 Area (java.awt.geom.Area)2 ArrayList (java.util.ArrayList)2 ShapeRoi (ij.gui.ShapeRoi)1 RoiManager (ij.plugin.frame.RoiManager)1 BinaryInterpolation2D (ini.trakem2.imaging.BinaryInterpolation2D)1 Polygon (java.awt.Polygon)1 Path2D (java.awt.geom.Path2D)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 ShapeListCached (mpicbg.imglib.container.shapelist.ShapeListCached)1