Java Code Examples for ij.gui.Roi#getType()

The following examples show how to use ij.gui.Roi#getType() . 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: PairWiseStitchingImgLib.java    From Stitching with GNU General Public License v2.0 5 votes vote down vote up
protected static Roi getOnlyRectangularRoi( Roi roi )
{
	// we can only do rectangular rois
	if ( roi != null && roi.getType() != Roi.RECTANGLE )
		return null;
	return roi;
}
 
Example 2
Source File: InteractiveDoG.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void mouseReleased( final MouseEvent e )
{
	// here the ROI might have been modified, let's test for that
	final Roi roi = imp.getRoi();
	
	if ( roi == null || roi.getType() != Roi.RECTANGLE )
		return;
	
	while ( isComputing )
		SimpleMultiThreading.threadWait( 10 );
	
	updatePreview( ValueChange.ROI );				
}
 
Example 3
Source File: M.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Returns true if the roi is of closed shape type like an OvalRoi, ShapeRoi, a Roi rectangle, etc. */
static public final boolean isAreaROI(final Roi roi) {
	switch (roi.getType()) {
		case Roi.POLYLINE:
		case Roi.FREELINE:
		case Roi.LINE:
		case Roi.POINT:
			return false;
	}
	return true;
}
 
Example 4
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 5
Source File: InteractiveDoG.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run( String arg )
{
	if ( imp == null )
		imp = WindowManager.getCurrentImage();
	
	standardRectangle = new Rectangle( imp.getWidth()/4, imp.getHeight()/4, imp.getWidth()/2, imp.getHeight()/2 );
	
	if ( imp.getType() == ImagePlus.COLOR_RGB || imp.getType() == ImagePlus.COLOR_256 )
	{			
		IJ.log( "Color images are not supported, please convert to 8, 16 or 32-bit grayscale" );
		return;
	}
	
	Roi roi = imp.getRoi();
	
	if ( roi == null )
	{
		//IJ.log( "A rectangular ROI is required to define the area..." );
		imp.setRoi( standardRectangle );
		roi = imp.getRoi();
	}
	
	if ( roi.getType() != Roi.RECTANGLE )
	{
		IJ.log( "Only rectangular rois are supported..." );
		return;
	}
	
	// copy the ImagePlus into an ArrayImage<FloatType> for faster access
	source = convertToFloat( imp, channel, 0, minIntensityImage, maxIntensityImage );
	
	// show the interactive kit
	displaySliders();

	// add listener to the imageplus slice slider
	sliceObserver = new SliceObserver( imp, new ImagePlusListener() );

	// compute first version
	updatePreview( ValueChange.ALL );		
	isStarted = true;
	
	// check whenever roi is modified to update accordingly
	roiListener = new RoiListener();
	imp.getCanvas().addMouseListener( roiListener );
}