Java Code Examples for ij.plugin.frame.RoiManager#add()

The following examples show how to use ij.plugin.frame.RoiManager#add() . 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: DetectCirclesJ_.java    From IJ-OpenCV with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {

    // Converters
    ImagePlusMatConverter ic = new ImagePlusMatConverter();
    opencv_core.Mat m = ic.convert(imp, Mat.class);
    MatListOvalRoiConverter cc = new MatListOvalRoiConverter();

    Mat gray = new Mat();
    opencv_imgproc.cvtColor(m, gray, opencv_imgproc.COLOR_BGR2GRAY);

    Mat circles = new Mat();
    opencv_imgproc.HoughCircles(gray, circles, opencv_imgproc.CV_HOUGH_GRADIENT, 1.2, 100);

    ArrayList<OvalRoi> or = new ArrayList<OvalRoi>();
    or = cc.convert(circles, or.getClass());

    RoiManager rm = new RoiManager();

    for (int i = 0; i < or.size(); i++) {
        rm.add(imp, or.get(i), i);
    }

}
 
Example 2
Source File: FaceDetectionJ_.java    From IJ-OpenCV with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
    //Converters
    RectRoiConverter rc = new RectRoiConverter();
    opencv_core.Mat img2 = ImagePlusMatConverter.toMat(imp, 8); // also does RGB to Gray automatically

    // Detect the faces and store them as an array of rectangles
    opencv_core.RectVector rv = detectFaces(img2);

    // Add rectangles to ROI Manager
    RoiManager rm = new RoiManager();
    rm.setVisible(true);
    for (int i = 0; i < rv.size(); i++) {
        Roi r = rc.convert(rv.get(i), Roi.class);
        rm.add(imp, r, 0);
    }
    
    //Show all ROI
    rm.runCommand("Show All");

}
 
Example 3
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 4
Source File: HoughLinesJ_.java    From IJ-OpenCV with GNU General Public License v3.0 5 votes vote down vote up
@Override
  public void run() {
 
// Do line detection
ArrayList<Line> linesIJ = HoughLines(imp, min_length, step_line, min_theta, max_theta, step_theta);

// Add lines to RoiManager
      RoiManager rm = new RoiManager();
      rm.setVisible(true);

      for (int i = 0; i < linesIJ.size(); i++) {
          rm.add(imp, linesIJ.get(i), i);
       }
}
 
Example 5
Source File: GeodesicDiameterPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Adds the specified paths to the list of ROI of the image plus.
 * 
 * @param target The ImagePlus that will be associated with ROIS
 * @param geodDiams the list of paths
 */
public void createPathRois(ImagePlus target, Map<Integer, GeodesicDiameter.Result> geodDiams)
{
	// get instance of ROI Manager
	RoiManager manager = RoiManager.getRoiManager();
	Calibration calib = target.getCalibration();
	
	// add each path to the ROI Manager
	int index = 0;
	for (GeodesicDiameter.Result result : geodDiams.values())
	{
	    manager.add(target, createPathRoi(result.path, calib), index++);
	}
}
 
Example 6
Source File: TemplateMatchingJ_.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run() {
    ImagePlus original = (ImagePlus) imp.clone();

    Roi r = imp.getRoi();

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

    if (r.isArea() && (r.getType() == Roi.RECTANGLE)) {

        // Crop the selection to be the template
        IJ.run(imp, "Crop", "");

        //Converters
        ImagePlusMatConverter ic = new ImagePlusMatConverter();
        RectRoiConverter rc = new RectRoiConverter();

        // Convert the ImageJ images to OpenCV images
        opencv_core.Mat matching = ic.convert(original, Mat.class);
        opencv_core.Mat template = ic.convert(imp, Mat.class);

        opencv_core.Mat gray = new opencv_core.Mat();
        opencv_imgproc.cvtColor(matching, gray, opencv_imgproc.COLOR_BGR2GRAY);
        opencv_imgproc.cvtColor(template, template, opencv_imgproc.COLOR_BGR2GRAY);

        opencv_core.Mat results = new opencv_core.Mat();

        // Matching and normalisation
        matchTemplate(gray, template, results, TM_CCOEFF_NORMED);
        normalize(results, results, 0, 1, NORM_MINMAX, -1, new opencv_core.Mat());

        DoublePointer minVal = new DoublePointer();
        DoublePointer maxVal= new DoublePointer();
        opencv_core.Point minLoc = new opencv_core.Point();
        opencv_core.Point maxLoc = new opencv_core.Point();
        opencv_core.Point matchLoc;

        minMaxLoc(results, minVal, maxVal, minLoc, maxLoc, new opencv_core.Mat());

        ArrayList<opencv_core.Point> locations = obtainLocations(results, 0.99, template.cols(), template.rows());
        RoiManager rm = new RoiManager();
        rm.setVisible(true);

        opencv_core.Rect solution;
        Roi solutionIJ;
        opencv_core.Point p;
        for (int i = 0; i < locations.size(); i++) {
            p = locations.get(i);
            solution = new opencv_core.Rect(p.x(), p.y(), template.cols(), template.rows());
            solutionIJ = rc.convert(solution, Roi.class);
            rm.add(original, solutionIJ, i);

        }

        imp.changes = false;
        imp.close();
        original.show();

    } else {
        IJ.error("Select a rectangle");
    }
}
 
Example 7
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);
    }
    
    
    

}