ij.gui.PolygonRoi Java Examples

The following examples show how to use ij.gui.PolygonRoi. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConvexHullFromPolygonROIJ_.java    From IJ-OpenCV with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
    // Get the ROI and check that it is a polygon
    PolygonRoi r = (PolygonRoi) imp.getRoi();

    if (r == null) {
        IJ.error("Select first a polygon ROI");
        return;
    }

    // Converter
    PolygonRoiMatConverter pc = new PolygonRoiMatConverter();
    MatPointRoiConverter mpc = new MatPointRoiConverter();

    Mat m = pc.convert(r, Mat.class);
    Mat convexHull = new Mat();
    opencv_imgproc.convexHull(m, convexHull);

    PolygonRoi pr = mpc.convert(convexHull, PolygonRoi.class);

    RoiManager rm = new RoiManager();
    rm.add(imp, r, 0);
    rm.add(imp, pr, 1);

}
 
Example #2
Source File: MaxFeretDiameterPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Roi createDiametersRoi(PointPair2D pointPair, Calibration calib)
{
	if (pointPair == null)
   	{
   		return null;
   	}

	Point2D p1 = calibToPixel(pointPair.p1, calib);
	Point2D p2 = calibToPixel(pointPair.p2, calib);
	
	// Convert to Polyline ROI
	float[] x = new float[2];
       float[] y = new float[2];
       x[0] = (float) p1.getX();
       y[0] = (float) p1.getY();
       x[1] = (float) p2.getX();
       y[1] = (float) p2.getY();
       return new PolygonRoi(x, y, 2, Roi.POLYLINE);
}
 
Example #3
Source File: Polygon2D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Converts this polygon into an ImageJ Polygon ROI.
 * 
 * @return the corresponding PolygonRoi
 */
public PolygonRoi createRoi()
{
	// allocate memory for data arrays
	int n = this.vertices.size();
	float[] px = new float[n];
	float[] py = new float[n];
	
	// extract coordinates
	for (int i = 0; i < n; i++)
	{
		Point2D p = this.vertices.get(i);
		px[i] = (float) p.getX();
		py[i] = (float) p.getY();
	}

	// create ROI data structure
	return new PolygonRoi(px, py, n, Roi.POLYGON);
}
 
Example #4
Source File: Path.java    From SNT with GNU General Public License v3.0 6 votes vote down vote up
private void addPolyLineToOverlay(final FloatPolygon p, final int z_position, final int roi_id,
		final Overlay overlay) {
	if (p.npoints > 0) {
		if (p.npoints == 1) {
			// create 1-pixel length lines for single points
			p.xpoints[0] -= 0.5f;
			p.ypoints[0] -= 0.5f;
			p.addPoint(p.xpoints[0] + 0.5f, p.ypoints[0] + 0.5f);
		}
		final PolygonRoi polyline = new PolygonRoi(p, Roi.FREELINE);
		polyline.enableSubPixelResolution();
		// polyline.fitSplineForStraightening();
		if (name == null)
			setDefaultName();
		polyline.setStrokeColor(getColor());
		polyline.setName(String.format(name + "-%04d-Z%d", roi_id, z_position));
		polyline.setPosition(z_position + 1); // index 1
		overlay.add(polyline);
	}
}
 
Example #5
Source File: MatPolygonRoiConverter.java    From IJ-OpenCV with GNU General Public License v3.0 6 votes vote down vote up
@Override
public < T> T convert(Object o, Class< T> type) {
    Mat m =(Mat)o;
    opencv_core.MatVector xy = new opencv_core.MatVector(2);
    split(m, xy);
    int h = m.size().height();
    int[] xpoints = new int[h];
    int[] ypoints = new int[h];

    for (int i = 0; i < h; i++) {
        xpoints[i] = xy.get(0).getIntBuffer().get(i);
        ypoints[i] = xy.get(1).getIntBuffer().get(i);
    }

    PolygonRoi pr = new PolygonRoi(xpoints, ypoints, h, Roi.POLYGON);
    return (T)pr;

}
 
Example #6
Source File: MatVectorListPolygonRoiConverter.java    From IJ-OpenCV with GNU General Public License v3.0 5 votes vote down vote up
@Override
public < T> T convert(Object o, Class< T> type) {
    MatVector mv = (MatVector) o;
    ArrayList<PolygonRoi> alproi = new ArrayList<PolygonRoi>();
    MatPolygonRoiConverter pg = new MatPolygonRoiConverter();
    for (int i = 0; i < mv.size(); i++) {
        alproi.add(pg.convert(mv.get(i), PolygonRoi.class));
    }
    return (T) alproi;

}
 
Example #7
Source File: OrientedBoundingBoxPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Determines the ROI corresponding to the uncalibrated version of this
 * box, assuming it was defined in calibrated coordinates.
 * 
 * @param box
 *            the oriented box in calibrated coordinates
 * @param calib
 *            the spatial calibration to consider
 * @return the ROI corresponding to the box
 */
private final static Roi createUncalibratedRoi(OrientedBox2D box, Calibration calib)
{
	Point2D center = box.center();
	double xc = center.getX();
	double yc = center.getY();
	double dx = box.length() / 2;
	double dy = box.width() / 2;
	double theta = Math.toRadians(box.orientation());
	double cot = Math.cos(theta);
	double sit = Math.sin(theta);
	
	// coordinates of polygon ROI
	float[] xp = new float[4];
	float[] yp = new float[4];
	
	// iterate over vertices
	double x, y;
	x = xc + dx * cot - dy * sit;
	y = yc + dx * sit + dy * cot;
	xp[0] = (float) ((x - calib.xOrigin) / calib.pixelWidth);
	yp[0] = (float) ((y - calib.yOrigin) / calib.pixelHeight);
	x = xc - dx * cot - dy * sit;
	y = yc - dx * sit + dy * cot;
	xp[1] = (float) ((x - calib.xOrigin) / calib.pixelWidth);
	yp[1] = (float) ((y - calib.yOrigin) / calib.pixelHeight);
	x = xc - dx * cot + dy * sit;
	y = yc - dx * sit - dy * cot;
	xp[2] = (float) ((x - calib.xOrigin) / calib.pixelWidth);
	yp[2] = (float) ((y - calib.yOrigin) / calib.pixelHeight);
	x = xc + dx * cot + dy * sit;
	y = yc + dx * sit - dy * cot;
	xp[3] = (float) ((x - calib.xOrigin) / calib.pixelWidth);
	yp[3] = (float) ((y - calib.yOrigin) / calib.pixelHeight);
	return new PolygonRoi(xp, yp, 4, Roi.POLYGON);
}
 
Example #8
Source File: InertiaEllipsePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
private final static Roi createRoi(Ellipse ellipse)
{
	// Coordinates of ellipse, in pixel coordinates
	Point2D center = ellipse.center();
	double xc = center.getX();
	double yc = center.getY();
	
	double r1 = ellipse.radius1();
	double r2 = ellipse.radius2();
	double theta = Math.toRadians(ellipse.orientation());
	
	double cot = Math.cos(theta);
	double sit = Math.sin(theta);
	
	int nVertices = 100;
	float[] xv = new float[nVertices];
	float[] yv = new float[nVertices];
	for (int i = 0; i < nVertices; i++)
	{
		double t = i * Math.PI * 2.0 / nVertices;
		double x = Math.cos(t) * r1;
		double y = Math.sin(t) * r2;
		
		xv[i] = (float) (x * cot - y * sit + xc);
		yv[i] = (float) (x * sit + y * cot + yc);
	}
	
	return new PolygonRoi(xv, yv, nVertices, Roi.POLYGON);
}
 
Example #9
Source File: EquivalentEllipsePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
private final static Roi createRoi(Ellipse ellipse)
{
	// Coordinates of ellipse, in pixel coordinates
	Point2D center = ellipse.center();
	double xc = center.getX();
	double yc = center.getY();
	
	double r1 = ellipse.radius1();
	double r2 = ellipse.radius2();
	double theta = Math.toRadians(ellipse.orientation());
	
	double cot = Math.cos(theta);
	double sit = Math.sin(theta);
	
	int nVertices = 100;
	float[] xv = new float[nVertices];
	float[] yv = new float[nVertices];
	for (int i = 0; i < nVertices; i++)
	{
		double t = i * Math.PI * 2.0 / nVertices;
		double x = Math.cos(t) * r1;
		double y = Math.sin(t) * r2;
		
		xv[i] = (float) (x * cot - y * sit + xc);
		yv[i] = (float) (x * sit + y * cot + yc);
	}
	
	return new PolygonRoi(xv, yv, nVertices, Roi.POLYGON);
}
 
Example #10
Source File: Point2fPolygonRoiConverter.java    From IJ-OpenCV with GNU General Public License v3.0 5 votes vote down vote up
@Override
public < T> T convert(Object o, Class< T> type) {
opencv_core.Point2f p = (opencv_core.Point2f) o;
    int[] xpoints = new int[p.sizeof() / 2];
    int[] ypoints = new int[p.sizeof() / 2];

    for (int i = 0; i < p.sizeof(); i = i + 2) {

        xpoints[i / 2] = (int) p.get(i);
        ypoints[i / 2] = (int) p.get(i + 1);
    }
    PolygonRoi pr = new PolygonRoi(xpoints, ypoints, p.sizeof() / 2, Roi.POLYGON);
    return (T)pr;
}
 
Example #11
Source File: RotatedRectPolygonRoiConverter.java    From IJ-OpenCV with GNU General Public License v3.0 5 votes vote down vote up
@Override
public < T> T convert(Object o, Class< T> type) {
    RotatedRect rr = (opencv_core.RotatedRect) o;
    double _angle = rr.angle() * Math.PI / 180.0;
    double b = (double) Math.cos(_angle) * 0.5f;
    double a = (double) Math.sin(_angle) * 0.5f;

    opencv_core.Point pt0 = new opencv_core.Point(
            (int) (rr.center().x() - a * rr.size().height() - b * rr.size().width()),
            (int) (rr.center().y() + b * rr.size().height() - a * rr.size().width()));

    opencv_core.Point pt1 = new opencv_core.Point(
            (int) (rr.center().x() + a * rr.size().height() - b * rr.size().width()),
            (int) (rr.center().y() - b * rr.size().height() - a * rr.size().width()));

    opencv_core.Point pt2 = new opencv_core.Point((int) (2 * rr.center().x() - pt0.x()),
            (int) (2 * rr.center().y() - pt0.y()));

    opencv_core.Point pt3 = new opencv_core.Point((int) (2 * rr.center().x() - pt1.x()),
            (int) (2 * rr.center().y() - pt1.y()));

    int[] xpoints = new int[4];
    int[] ypoints = new int[4];

    xpoints[0] = pt0.x();
    ypoints[0] = pt0.y();
    xpoints[1] = pt1.x();
    ypoints[1] = pt1.y();
    xpoints[2] = pt2.x();
    ypoints[2] = pt2.y();
    xpoints[3] = pt3.x();
    ypoints[3] = pt3.y();

    PolygonRoi pr = new PolygonRoi(xpoints, ypoints, 4, Roi.POLYGON);
    return (T)pr;

}
 
Example #12
Source File: ListPolygonRoiMatVectorConverter.java    From IJ-OpenCV with GNU General Public License v3.0 5 votes vote down vote up
@Override
public < T> T convert(Object o, Class< T> type) {
    ArrayList<PolygonRoi> aproi = (ArrayList<PolygonRoi>) o;
    opencv_core.MatVector mv = new opencv_core.MatVector(aproi.size());
    PolygonRoiMatConverter pg = new PolygonRoiMatConverter();

    for (int i = 0; i < aproi.size(); i++) {
        mv.put(i, pg.convert(aproi.get(i), Mat.class));
    }
    return (T) mv;

}
 
Example #13
Source File: PolygonRoiRotatedRectConverter.java    From IJ-OpenCV with GNU General Public License v3.0 5 votes vote down vote up
@Override
public < T> T convert(Object o, Class< T> type) {
PolygonRoi pr = (PolygonRoi)o;
    PolygonRoiMatConverter pg = new PolygonRoiMatConverter();
    opencv_core.Mat points = pg.convert(pr,Mat.class);
    opencv_core.RotatedRect rr = opencv_imgproc.minAreaRect(points);
    return (T)rr;
}
 
Example #14
Source File: PolygonRoiRotatedRectConverter.java    From IJ-OpenCV with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canConvert(Object src, Type dest) {
            if(!(src instanceof PolygonRoi)){
        return false;
    }
    PolygonRoi pr =(PolygonRoi)src;
 if(!pr.isArea() || pr.getPolygon().npoints != 4 ){
        return false;
    }
    return true;
}
 
Example #15
Source File: PolygonRoiMatConverter.java    From IJ-OpenCV with GNU General Public License v3.0 5 votes vote down vote up
@Override
public < T> T convert(Object o, Class< T> type) {
    PolygonRoi pr =(PolygonRoi)o;
    Mat mx = new Mat(pr.getPolygon().xpoints);
    Mat my = new Mat(pr.getPolygon().ypoints);
    opencv_core.MatVector mxy = new opencv_core.MatVector(2);
    mxy.put(0, mx);
    mxy.put(1, my);
    Mat m = new Mat();
    merge(mxy, m);
    return (T)m;
}
 
Example #16
Source File: PolygonRoiPoint2fConverter.java    From IJ-OpenCV with GNU General Public License v3.0 5 votes vote down vote up
@Override
  public < T> T convert(Object o, Class< T> type) {
PolygonRoi pr = (PolygonRoi)o;
           opencv_core.Point2f res = new opencv_core.Point2f();
      int[] xpoints = pr.getPolygon().xpoints;
      int[] ypoints = pr.getPolygon().ypoints;
      for (int i = 0; i < xpoints.length; i++) {
          opencv_core.Point2f p = new opencv_core.Point2f(xpoints[i], ypoints[i]);
          res.put(p);
      }
      return (T)res;
  }
 
Example #17
Source File: M.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
/** Returns an array of two Area objects, or of 1 if the @param proi doesn't intersect @param a. */
public static final Area[] splitArea(final Area a, final PolygonRoi proi, final Rectangle world) {
	if (!a.getBounds().intersects(proi.getBounds())) return new Area[]{a};

	final int[] x = proi.getXCoordinates(),
		  y = proi.getYCoordinates();
	final Rectangle rb = proi.getBounds();
	final int len = proi.getNCoordinates();
	final int x0 = x[0] + rb.x;
	final int y0 = y[0] + rb.y;
	final int xN = x[len -1] + rb.x;
	final int yN = y[len -1] + rb.y;

	// corners, clock-wise:
	final int[][] corners = new int[][]{new int[]{world.x, world.y}, // top left
								  new int[]{world.x + world.width, world.y}, // top right
								  new int[]{world.x + world.width, world.y + world.height}, // bottom right
								  new int[]{world.x, world.y + world.height}}; // bottom left
	// Which corner is closest to x0,y0, and which to xN,yN
	double min_dist0 = Double.MAX_VALUE;
	int min_i0 = 0;
	int i = 0;
	double min_distN = Double.MAX_VALUE;
	int min_iN = 0;
	for (final int[] corner : corners) {
		double d = distance(x0, y0, corner[0], corner[1]);
		if (d < min_dist0) {
			min_dist0 = d;
			min_i0 = i;
		}
		d = distance(xN, yN, corner[0], corner[1]);
		if (d < min_distN) {
			min_distN = d;
			min_iN = i;
		}
		i++;
	}
	// Create new Area 'b' with which to intersect Area 'a':
	int[] xb, yb;
	int l,
	    i1;
       final int i2 = -1;
	// 0 1 2 3: when there difference is 2, there is a point in between
	if (2 != Math.abs(min_iN - min_i0)) {
		l = len +4;
		xb = new int[l];
		yb = new int[l];
		// -4 and -1 will be the drifted corners
		i1 = -4;
		xb[l-4] = corners[min_iN][0];
		yb[l-4] = corners[min_iN][1];
		xb[l-3] = corners[min_iN][0];
		yb[l-3] = corners[min_iN][1];
		xb[l-2] = corners[min_i0][0];
		yb[l-2] = corners[min_i0][1];
		xb[l-1] = corners[min_i0][0];
		yb[l-1] = corners[min_i0][1];
	} else {
		l = len +5;
		xb = new int[l];
		yb = new int[l];
		// -5 and -1 will be the drifted corners
		i1 = -5;
		xb[l-5] = corners[min_iN][0];
		yb[l-5] = corners[min_iN][1];
		xb[l-4] = corners[min_iN][0];
		yb[l-4] = corners[min_iN][1];
		xb[l-3] = corners[(min_iN + min_i0) / 2][0];
		yb[l-3] = corners[(min_iN + min_i0) / 2][1];
		xb[l-2] = corners[min_i0][0];
		yb[l-2] = corners[min_i0][1];
		xb[l-1] = corners[min_i0][0];
		yb[l-1] = corners[min_i0][1];
	}
	// Enter polyline points, corrected for proi bounds
	for (int k=0; k<len; k++) {
		xb[k] = x[k] + rb.x;
		yb[k] = y[k] + rb.y;
	}
	// Drift corners to closest point on the sides
	// Last:
	int dx = Math.abs(xb[l+i1] - (x[len-1] + rb.x)),
	    dy = Math.abs(yb[l+i1] - (y[len-1] + rb.y));
	if (dy < dx) xb[l+i1] = x[len-1] + rb.x;
	else yb[l+i1] = y[len-1] + rb.y;
	// First:
	dx = Math.abs(xb[l+i2] - (x[0] + rb.x));
	dy = Math.abs(yb[l+i2] - (y[0] + rb.y));
	if (dy < dx) xb[l+i2] = x[0] + rb.x;
	else yb[l+i2] = y[0] + rb.y;

	final Area b = new Area(new Polygon(xb, yb, xb.length));
	final Area c = new Area(world);
	c.subtract(b);

	return new Area[]{b, c};
}
 
Example #18
Source File: ListPolygonRoiMatVectorConverter.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class< List<PolygonRoi>> getInputType() {
    return (Class<List<PolygonRoi>>) (Object) List.class;
}
 
Example #19
Source File: Segmentation.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
static public Bureaucrat magicWand(final AreaWrapper aw, final Layer layer, final Rectangle srcRect, final int x_p_w, final int y_p_w, final List<Runnable> post_tasks, final boolean inverse, final boolean subtract) {
	// Capture pointers before they are set to null
	final AreaContainer ac = (AreaContainer) aw.getSource();
	final AffineTransform source_aff = aw.getSource().getAffineTransform();
	final Rectangle box = new Rectangle(x_p_w - Segmentation.fmp.width/2, y_p_w - Segmentation.fmp.height/2, Segmentation.fmp.width, Segmentation.fmp.height);

	Bureaucrat burro = Bureaucrat.create(new Worker.Task("Magic Wand") { public void exec() {
		// Capture image as large as the fmp width,height centered on x_p_w,y_p_w
		Utils.log2("fmp box is " + box);
		ImageProcessor ip = Patch.makeFlatImage(ImagePlus.GRAY8, layer, box, 1.0, (Collection)layer.getDisplayables(Patch.class, new Area(box), true), Color.black);
		// Apply wand
		Wand wand = new Wand(ip);
		String smode = WandToolOptions.getMode();
		int mode = Wand.LEGACY_MODE;
		if (null == smode) {}
		else if (smode.startsWith("4")) mode = Wand.FOUR_CONNECTED;
		else if (smode.startsWith("8")) mode = Wand.EIGHT_CONNECTED;
		wand.autoOutline(ip.getWidth()/2, ip.getHeight()/2, WandToolOptions.getTolerance(), mode); // 8-bit image

		if (wand.npoints > 0) {
			Area area = M.getArea(new PolygonRoi(wand.xpoints, wand.ypoints, wand.npoints, PolygonRoi.FREEROI));
			if (inverse) {
				Area b = new Area(new Rectangle(0, 0, box.width, box.height));
				b.subtract(area);
				area = b;
			}

			// Compose an Area that is local to the AreaWrapper's area
			final AffineTransform aff = new AffineTransform(1, 0, 0, 1, box.x, box.y);
			try {
				aff.preConcatenate(source_aff.createInverse());
			} catch (NoninvertibleTransformException nite) {
				IJError.print(nite);
				return;
			}

			area.transform(aff);

			if (subtract) aw.getArea().subtract(area);
			else aw.getArea().add(area);

			ac.calculateBoundingBox(layer);

			Display.repaint(layer);
		}
	}}, layer.getProject());
	if (null != post_tasks) for (Runnable task : post_tasks) burro.addPostTask(task);
	burro.goHaveBreakfast();
	return burro;
}
 
Example #20
Source File: PolygonRoiRotatedRectConverter.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class< PolygonRoi> getInputType() {
    return PolygonRoi.class;
}
 
Example #21
Source File: PolygonRoiPoint2fConverter.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class< PolygonRoi> getInputType() {
    return PolygonRoi.class;
}
 
Example #22
Source File: ObjectFeatureBuilderTiled.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
/**
 * returns ShapeNames features (>= model version 10)
 *
 * @param shape
 * @return
 */
private List<Double> getFeatureShapeDescriptorsNew(Shape shape) {
    List<Double> feats = new ArrayList<Double>(getShapeNames().length);
    double ratio = Double.NaN;
    double perimeter = Double.NaN;
    double area = Double.NaN;
    double circularity = Double.NaN;
    double solidity = Double.NaN;
    double convexity = Double.NaN;
    double compactness = Double.NaN;
    double roundness = Double.NaN;
    double centerX = Double.NaN;
    double centerY = Double.NaN;
    double centroidX = Double.NaN;
    double centroidY = Double.NaN;
    if (shape instanceof Polygon) {
        Polygon p = (Polygon) shape;
        PolygonMetrics pm = new PolygonMetrics(p);
        PolygonRoi pr = new PolygonRoi(p, Roi.POLYGON);
        Polygon convexHull = pr.getConvexHull();
        double[] ferets = pr.getFeretValues();
        double majorAxis = ferets[0];
        //double minorAxis = ferets[2];

        area = pm.getArea();
        perimeter = pm.getPerimeter();
        roundness = pm.getRoundnessNew(area, majorAxis);
        circularity = pm.getCircularity(area, perimeter);
        solidity = pm.getSolidity(convexHull, area);
        convexity = pm.getConvexity(convexHull, perimeter);
        compactness = pm.getCompactness(area, majorAxis);
        ratio = pm.getAspectRatio(ferets);

        // centerX/Y
        Point2D center = pm.getCenter();
        centerX = Math.abs(center.getX());
        centerY = Math.abs(center.getY());

    }

    feats.add(roundness);
    feats.add(circularity);
    feats.add(solidity);
    feats.add(convexity);
    feats.add(compactness);
    feats.add(area);
    feats.add(perimeter);
    feats.add(ratio);
    feats.add(centerX);
    feats.add(centerY);
    return feats;
}
 
Example #23
Source File: Point2fPolygonRoiConverter.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class< PolygonRoi> getOutputType() {
    return PolygonRoi.class;
}
 
Example #24
Source File: MatPolygonRoiConverter.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class< PolygonRoi> getOutputType() {
    return PolygonRoi.class;
}
 
Example #25
Source File: PolygonRoiMatConverter.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class< PolygonRoi> getInputType() {
    return PolygonRoi.class;
}
 
Example #26
Source File: MatVectorListPolygonRoiConverter.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class< List<PolygonRoi>> getOutputType() {
    return (Class<List<PolygonRoi>>) (Object) List.class;
}
 
Example #27
Source File: RotatedRectFromPolygonROIJ_.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run() {
    PolygonRoi pr = (PolygonRoi) imp.getRoi();
    // Converters
    PolygonRoiMatConverter pc = new PolygonRoiMatConverter();
    RotatedRectPolygonRoiConverter p2c = new RotatedRectPolygonRoiConverter();

    Mat m = pc.convert(pr,Mat.class);

    opencv_core.RotatedRect rr = opencv_imgproc.minAreaRect(m);
    opencv_core.Point2f pt = new opencv_core.Point2f(9);

    rr.points(pt);

    PolygonRoi newpr = p2c.convert(pt,PolygonRoi.class);

    imp.setRoi(newpr);

}
 
Example #28
Source File: RotatedRectPolygonRoiConverter.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class< PolygonRoi> getOutputType() {
    return PolygonRoi.class;
}
 
Example #29
Source File: FindContoursJ_.java    From IJ-OpenCV with GNU General Public License v3.0 3 votes vote down vote up
@Override
public void run() {
    
    // Converters
    ImagePlusMatConverter ic = new ImagePlusMatConverter();

    opencv_core.Mat m = ic.convert(imp,opencv_core.Mat.class);
    MatVectorListPolygonRoiConverter pc = new MatVectorListPolygonRoiConverter();
    
    
    opencv_core.Mat gray = new opencv_core.Mat();
    opencv_imgproc.cvtColor(m,gray,opencv_imgproc.COLOR_BGR2GRAY);
    
    MatVector contours = new opencv_core.MatVector();
    
    opencv_imgproc.findContours(gray,contours,opencv_imgproc.RETR_LIST,opencv_imgproc.CHAIN_APPROX_SIMPLE);
    
    ArrayList<PolygonRoi> contoursROI = new ArrayList<PolygonRoi>();
    contoursROI= pc.convert(contours,contoursROI.getClass());
    
     // Add rectangles to ROI Manager
    RoiManager rm = new RoiManager();
    rm.setVisible(true);
    for (PolygonRoi contoursROI1 : contoursROI) {
        rm.add(imp, contoursROI1, 0);
    }
    
    
    

}