ij.gui.Roi Java Examples

The following examples show how to use ij.gui.Roi. 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: EquivalentEllipsePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private final static Roi createMinorAxisRoi(Ellipse ellipse)
{
	// Coordinates of ellipse, in pixel coordinates
	Point2D center = ellipse.center();
	double xc = center.getX();
	double yc = center.getY();
	
	double r2 = ellipse.radius2();
	double theta = Math.toRadians(ellipse.orientation() + 90);
	
	double cot = Math.cos(theta);
	double sit = Math.sin(theta);
	
	double x1 = xc + r2 * cot;
	double y1 = yc + r2 * sit;
	double x2 = xc - r2 * cot;
	double y2 = yc - r2 * sit;
	return new Line(x1, y1, x2, y2);
}
 
Example #2
Source File: Segmentation.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
public void finish(final AreaContainer ac, final AffineTransform source_aff) throws Exception {
	Roi roi = imp.getRoi();
	Utils.log2("roi is " + roi);
	if (null == roi) return;
	ShapeRoi sroi = new ShapeRoi(roi);
	Rectangle b = sroi.getBounds();
	sroi.setLocation(box.x + b.x, box.y + b.y);

	try {
		aw.getArea().add(M.getArea(sroi).createTransformedArea(source_aff.createInverse()));
		ac.calculateBoundingBox(layer);
		Display.getFront().getCanvas().getFakeImagePlus().killRoi();
	} catch (NoninvertibleTransformException nite) {
		IJError.print(nite);
	}
}
 
Example #3
Source File: Segmentation.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
public void moveBlow(int dx, int dy) throws Exception {
	int x = box.width/2 + dx;
	int y = box.height/2 + dy;
	// Keep within bounds
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	if (x > box.width -1) x = box.width -1;
	if (y > box.height -1) y = box.height -1;
	lasso.moveBlow(x, y);
	// extract ROI
	Roi roi = imp.getRoi();
	if (null == roi) Display.getFront().getCanvas().getFakeImagePlus().setRoi(roi); // can't set to null? Java, gimme a break
	else {
		Roi sroi = new ShapeRoi(roi);
		Rectangle b = sroi.getBounds();
		sroi.setLocation(box.x + b.x, box.y + b.y);
		Display.getFront().getCanvas().getFakeImagePlus().setRoi(sroi);
	}
}
 
Example #4
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 #5
Source File: InertiaEllipsePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private final static Roi createMajorAxisRoi(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 theta = Math.toRadians(ellipse.orientation());
	
	double cot = Math.cos(theta);
	double sit = Math.sin(theta);
	
	double x1 = xc + r1 * cot;
	double y1 = yc + r1 * sit;
	double x2 = xc - r1 * cot;
	double y2 = yc - r1 * sit;
	return new Line(x1, y1, x2, y2);
}
 
Example #6
Source File: InteractiveMarkerControlledWatershed.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Merge labels selected by free-hand or point ROIs
 */
void mergeLabels()
{
	if( resultImage == null )
	{
		IJ.error( "You need to run the segmentation before merging "
				+ "labels!" );
		return;
	}
	final Roi roi = displayImage.getRoi();
	if( roi == null )
	{
		IJ.showMessage( "Please select some labels to merge using any "
				+ "of the selection tools" );
		return;
	}

	// merge labels under the ROI
	LabelImages.mergeLabels( resultImage, roi, true );

	if ( showColorOverlay )
		updateResultOverlay();

	// macro recording
	record( MERGE_LABELS );
}
 
Example #7
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 #8
Source File: InertiaEllipsePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private final static Roi createMinorAxisRoi(Ellipse ellipse)
{
	// Coordinates of ellipse, in pixel coordinates
	Point2D center = ellipse.center();
	double xc = center.getX();
	double yc = center.getY();
	
	double r2 = ellipse.radius2();
	double theta = Math.toRadians(ellipse.orientation() + 90);
	
	double cot = Math.cos(theta);
	double sit = Math.sin(theta);
	
	double x1 = xc + r2 * cot;
	double y1 = yc + r2 * sit;
	double x2 = xc - r2 * cot;
	double y2 = yc - r2 * sit;
	return new Line(x1, y1, x2, y2);
}
 
Example #9
Source File: InteractiveMorphologicalReconstruction.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Called at the beginning of the process to know if the plugin can be run
 * with current image, and at the end to finalize.
 */
public int setup(String arg, ImagePlus imp)
{
	if( null == imp )
		return DONE;
	// Special case of plugin called to finalize the process
	if ( arg.equals("final") ) {
		// replace the preview image by the original image
		imagePlus.setProcessor( baseImage );
		imagePlus.draw();

		if( null != result )
		{
			// Create a new ImagePlus with the filter result
			String newName = createResultImageName( imagePlus );
			ImagePlus resPlus = new ImagePlus( newName, result );
			resPlus.copyScale( imagePlus );
			resPlus.show();
		}
		Roi.removeRoiListener( listener );
		return DONE;
	}

	return flags;
}
 
Example #10
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 #11
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 #12
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 #13
Source File: Coloc_2.java    From Colocalisation_Analysis with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates appropriate data structures from the ROI information
 * passed. If an irregular ROI is found, it will be put into a
 * frame of its bounding box size and put into an {@code Image<T>}.
 *
 * In the end the members ROIs, masks and maskBBs will be
 * filled if ROIs or masks were found. They will be null
 * otherwise.
 */
protected void createMasksAndRois(final Roi[] rois, final int width,
	final int height)
{
	// create empty list
	masks.clear();

	for (final Roi r : rois) {
		final MaskInfo mi = new MaskInfo();
		// add it to the list of masks/ROIs
		masks.add(mi);
		// get the ROIs/masks bounding box
		final Rectangle rect = r.getBounds();
		mi.roi = new BoundingBox(new long[] { rect.x, rect.y }, new long[] {
			rect.width, rect.height });
		final ImageProcessor ipMask = r.getMask();
		// check if we got a regular ROI and return if so
		if (ipMask == null) {
			continue;
		}

		// create a mask processor of the same size as a slice
		final ImageProcessor ipSlice = ipMask.createProcessor(width, height);
		// fill the new slice with black
		ipSlice.setValue(0.0);
		ipSlice.fill();
		// position the mask on the new mask processor
		ipSlice.copyBits(ipMask, (int) mi.roi.offset[0], (int) mi.roi.offset[1],
			Blitter.COPY);
		// create an Image<T> out of it
		final ImagePlus maskImp = new ImagePlus("Mask", ipSlice);
		// and remember it and the masks bounding box
		mi.mask = ImagePlusAdapter.<T> wrap(maskImp);
	}
}
 
Example #14
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 #15
Source File: LabelImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Remove labels selected by freehand or point ROIs (in place).
 *
 * @param labelImage  input label image
 * @param roi  FreehandRoi or PointRoi with selected labels
 * @param verbose  flag to print deleted labels in log window
 */
public static void removeLabels(
		final ImagePlus labelImage,
		final Roi roi,
		final boolean verbose )
{
	if( roi == null )
	{
		IJ.showMessage( "Please select at least one label to be removed"
				+ " using the freehand or point selection tools." );
		return;
	}

	final ArrayList<Float> list = getSelectedLabels( labelImage, roi );

	if( list.size() > 0 )
	{
		// move list values into an array
		float[] labelArray = new float[ list.size() ];
		int i = 0;
		for ( Float f : list )
			labelArray[ i++ ] = f != null ? f : Float.NaN;

		String sLabels = new String( ""+ (long) labelArray[ 0 ] );
		for( int j=1; j < labelArray.length; j++ )
			sLabels += ", " + (long) labelArray[ j ];
		if( verbose )
			IJ.log( "Removing label(s) " + sLabels + "..." );

		LabelImages.replaceLabels( labelImage,
				labelArray, 0 );
	}
	else
		IJ.error( "Please select at least one label to remove." );
}
 
Example #16
Source File: LabelImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Merge labels selected by freehand or point tool. Labels are merged
 * in place (i.e., the input image is modified). Zero-value label is never
 * merged.
 *
 * @param labelImage  label image to modify
 * @param roi  selection indicating the labels to merge
 * @param verbose  option to write in the log window the labels merged
 */
public static final void mergeLabels(
		final ImagePlus labelImage,
		final Roi roi,
		final boolean verbose )
{
	if( roi == null )
	{
		IJ.showMessage( "Please select some labels to merge using the "
				+ "freehand or point selection tool." );
		return;
	}

	final ArrayList<Float> list = getSelectedLabels( labelImage, roi );

	// if more than one value is selected, merge
	if( list.size() > 1 )
	{
		float finalValue = list.remove( 0 );
		float[] labelArray = new float[ list.size() ];
		int i = 0;

		for ( Float f : list )
			labelArray[i++] = f != null ? f : Float.NaN;

		String sLabels = new String( ""+ (long) labelArray[ 0 ] );
		for( int j=1; j < labelArray.length; j++ )
			sLabels += ", " + (long) labelArray[ j ];
		if( verbose )
			IJ.log( "Merging label(s) " + sLabels + " to label "
						+ (long) finalValue );
		LabelImages.replaceLabels( labelImage,
				labelArray, finalValue );
	}
	else
		IJ.error( "Please select two or more different"
				+ " labels to merge" );
}
 
Example #17
Source File: Patch.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mousePressed(final MouseEvent me, final Layer la, final int x_p, final int y_p, final double mag) {
	final int tool = ProjectToolbar.getToolId();
	final DisplayCanvas canvas = (DisplayCanvas)me.getSource();
	if (ProjectToolbar.WAND == tool) {
		if (null == canvas) return;
		Bureaucrat.createAndStart(new Worker.Task("Magic Wand ROI") {
			@Override
			public void exec() {
				final PatchImage pai = createTransformedImage();
				pai.target.setMinAndMax(min, max);
				final ImagePlus patchImp = new ImagePlus("", pai.target.convertToByte(true));
				final double[] fp = new double[2];
				fp[0] = x_p;
				fp[1] = y_p;
				try {
					at.createInverse().transform(fp, 0, fp, 0, 1);
				} catch (final NoninvertibleTransformException e) {
					IJError.print(e);
					return;
				}
				final int npoints = IJ.doWand(patchImp, (int)fp[0], (int)fp[1], WandToolOptions.getTolerance(), WandToolOptions.getMode());
				if (npoints > 0) {
					System.out.println("npoints " + npoints);
					final Roi roi = patchImp.getRoi();
					if (null != roi) {
						final Area aroi = M.getArea(roi);
						aroi.transform(at);
						canvas.getFakeImagePlus().setRoi(new ShapeRoi(aroi));
					}
				}
			}
		}, project);
	}
}
 
Example #18
Source File: Stitching_3D.java    From Stitching with GNU General Public License v2.0 5 votes vote down vote up
private Point3D getImageOffset(CrossCorrelationResult3D result, ImagePlus imp1, ImagePlus imp2)
{
	// see "ROI shift to Image Shift.ppt" for details of nomenclature
	Point3D r1, r2, sr, sir, si;

	// relative shift between rois (all shifts relative to upper left front
	// corner)
	sr = result.shift;

	if (imp1.getRoi() == null || imp2.getRoi() == null)
	{
		// there are no rois....so we already have the relative shift
		// between the images
		si = sr;
	}
	else
	{
		Roi roi1 = imp1.getRoi();
		Roi roi2 = imp2.getRoi();

		int x1 = roi1.getBoundingRect().x;
		int y1 = roi1.getBoundingRect().y;
		int x2 = roi2.getBoundingRect().x;
		int y2 = roi2.getBoundingRect().y;

		r1 = new Point3D(x1, y1, 0);
		r2 = new Point3D(x2, y2, 0);

		sir = add(r1, sr);
		si = subtract(sir, r2);
	}

	return si;
}
 
Example #19
Source File: PatchStack.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public ImageProcessor getMask() {
	ImagePlus imp = patch[currentSlice-1].getProject().getLoader().fetchImagePlus(patch[currentSlice-1]);
	ImageProcessor ip = imp.getProcessor();
	Roi roi = getRoi();
	if (null == roi) {
		ip.resetRoi();
		return null;
	}
	ImageProcessor mask = roi.getMask();
	if (null==mask) return null;
	ip.setMask(mask);
	ip.setRoi(roi.getBounds());
	return mask;
}
 
Example #20
Source File: Stitching_2D.java    From Stitching with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkRoi(ImagePlus imp1, ImagePlus imp2)
{
	boolean img1HasROI, img2HasROI;

	if (imp1.getRoi() != null)
		img1HasROI = true;
	else
		img1HasROI = false;

	if (imp2.getRoi() != null)
		img2HasROI = true;
	else
		img2HasROI = false;

	if (img1HasROI && !img2HasROI || img2HasROI && !img1HasROI)
	{
		IJ.error("Eigher both images should have a ROI or none of them.");

		return false;
	}

	if (img1HasROI)
	{
		int type1 = imp1.getRoi().getType();
		int type2 = imp2.getRoi().getType();

		if (type1 != Roi.RECTANGLE)
		{
			IJ.error(imp1.getTitle() + " has a ROI which is no rectangle.");
		}

		if (type2 != Roi.RECTANGLE)
		{
			IJ.error(imp2.getTitle() + " has a ROI which is no rectangle.");
		}
	}

	return true;
}
 
Example #21
Source File: AstigmaticBiplaneCalibrationProcess.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public AstigmaticBiplaneCalibrationProcess(CalibrationConfig config, IFilterUI selectedFilterUI, IDetectorUI selectedDetectorUI,
                                           AstigmaticBiplaneCalibrationEstimatorUI calibrationEstimatorUI, DefocusFunction defocusModel,
                                           double stageStep, double zRangeLimit, ImagePlus imp1, ImagePlus imp2, Roi roi1, Roi roi2) {
    super(config, selectedFilterUI, selectedDetectorUI, calibrationEstimatorUI, defocusModel, stageStep, zRangeLimit);
    this.imp1 = imp1;
    this.imp2 = imp2;
    this.roi1 = roi1;
    this.roi2 = roi2;
}
 
Example #22
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 #23
Source File: MatchIntensities.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
private static Rectangle getRoi( final LayerSet layerset )
{
	final Roi roi;
	final Display front = Display.getFront();
	if ( front == null )
		roi = null;
	else
		roi = front.getRoi();
	if ( roi == null )
		return new Rectangle( 0, 0, ( int ) layerset.getLayerWidth(), ( int ) layerset.getLayerHeight() );
	else
		return roi.getBounds();
}
 
Example #24
Source File: GeodesicDiameterPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void drawPaths(ImagePlus target, Map<Integer, GeodesicDiameter.Result> geodDiams)
{
	Overlay overlay = new Overlay();
	Calibration calib = target.getCalibration();
	
	for (GeodesicDiameter.Result result : geodDiams.values())
	{
		Roi roi = createPathRoi(result.path, calib);
	    roi.setStrokeColor(Color.RED);
	    overlay.add(roi);
	}

	target.setOverlay(overlay);
}
 
Example #25
Source File: InteractiveProjections.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void actionPerformed( final ActionEvent arg0 )
{
	final Roi roi = imp.getRoi();

	if ( roi == null )
	{
		IOFunctions.println( "No ROI selected in max projection image." );
	}
	else
	{
		int count = ipList.size();

		for ( int i = ipList.size() - 1; i >= 0; --i )
		{
			final double[] l = ipList.get( i ).getL();

			final boolean contains = roi.contains( (int)Math.round( l[ xDim ] ), (int)Math.round( l[ yDim ] ) );
			
			if ( inside && contains || !inside && !contains )
				ipList.remove( i );
		}

		drawProjectedInterestPoints( imp, ipList, projectionDim );

		IOFunctions.println( "(" + new Date( System.currentTimeMillis() ) + ": " + ipList.size() + " points remaining, removed " + (count - ipList.size()) + " points ... " );
	}
}
 
Example #26
Source File: AnalyzeSkeleton_.java    From AnalyzeSkeleton with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check if the point is an 'unprotected' end point.
 *
 * @param point actual point
 * @param roi Only points outside this ROI will have end-point status. ROI
 *            can be associated to a single image in the stack (or all) as
 *            per {@link ij.gui.Roi#getPosition ij.gui.Roi.getPosition()}
 * @return true if the point has end-point status
 */
private boolean isEndPoint(Point point, Roi roi)
{
	boolean endPoint = isEndPoint(point);
	if (endPoint && roi != null)
	{
		// Is roi associated with all the images in the ImageStack?
		boolean roiContainsZ = (roi.getPosition()==0) ? true : roi.getPosition()==point.z;

		// Maintain end-point status only if point lies outside roi boundaries
		endPoint = !(roi.contains(point.x, point.y) && roiContainsZ);
	}
	return endPoint;
}
 
Example #27
Source File: ResultsFilter.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public void restrictToROIFilter() {
    double mag = new EmptyRendererUI().magnification.getValue();
    IJResultsTable rt = IJResultsTable.getResultsTable();
    ImagePlus preview = rt.getPreviewImage();
    Roi roi2 = null;
    if(preview != null) {
        roi2 = preview.getRoi();
    }
    if(roi2 == null) {
        GUI.showBalloonTip(restrictToROIButton, "There is no ROI in the preview image!");
        return;
    }
    Rectangle2D[] rectangleList;
    if(roi2 instanceof ShapeRoi) {
        ShapeRoi shapeRoi = (ShapeRoi) roi2;
        Roi[] roiList = shapeRoi.getRois();
        rectangleList = new Rectangle2D[roiList.length];
        for(int i = 0; i < roiList.length; i++) {
            rectangleList[i] = roiList[i].getBounds();
        }
    } else {
        rectangleList = new Rectangle2D[]{roi2.getBounds()};
    }
    Units ux = rt.getColumnUnits(LABEL_X);
    Units uy = rt.getColumnUnits(LABEL_Y);
    //
    for(int i = 0; i < rectangleList.length; i++) {
        rectangleList[i] = convertRectangleUnits(rectangleList[i], ux, uy, mag);
    }
    addNewRectanglesFilter(rectangleList);
}
 
Example #28
Source File: Loader.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Workaround for ImageJ's ImagePlus.flush() method which calls the System.gc() unnecessarily.
 * <p>
 * A null pointer as argument is accepted.
 * </p>
 */
static public final void flush(final ImagePlus imp) {
	if (null == imp) return;
	final Roi roi = imp.getRoi();
	if (null != roi) roi.setImage(null);
	//final ImageProcessor ip = imp.getProcessor(); // the nullifying makes no difference, and in low memory situations some bona fide imagepluses may end up failing on the calling method because of lack of time to grab the processor etc.
	//if (null != ip) ip.setPixels(null);
	ipa.notifyListeners(imp, ipa.CLOSE);
}
 
Example #29
Source File: AstigmaticCalibrationProcess.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public AstigmaticCalibrationProcess(CalibrationConfig config, IFilterUI selectedFilterUI, IDetectorUI selectedDetectorUI,
                                    AstigmatismCalibrationEstimatorUI calibrationEstimatorUI, DefocusFunction defocusModel,
                                    double stageStep, double zRangeLimit, ImagePlus imp, Roi roi) {
    super(config, selectedFilterUI, selectedDetectorUI, calibrationEstimatorUI, defocusModel, stageStep, zRangeLimit);
    this.imp = imp;
    this.roi = roi;
}
 
Example #30
Source File: CalibrationProcessFactory.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static AbstractCalibrationProcess create(CalibrationConfig config, IFilterUI selectedFilterUI, IDetectorUI selectedDetectorUI, ICalibrationEstimatorUI calibrationEstimatorUI,
                                               DefocusFunction defocusModel, double stageStep, double zRangeLimit, ImagePlus imp1, ImagePlus imp2, Roi roi1, Roi roi2) {
    if (calibrationEstimatorUI instanceof BiplaneCalibrationEstimatorUI) {
        return new BiplaneCalibrationProcess(config, selectedFilterUI, selectedDetectorUI, (BiplaneCalibrationEstimatorUI) calibrationEstimatorUI, defocusModel, stageStep, zRangeLimit, imp1, imp2, roi1, roi2);
    } else if (calibrationEstimatorUI instanceof AstigmaticBiplaneCalibrationEstimatorUI) {
        return new AstigmaticBiplaneCalibrationProcess(config, selectedFilterUI, selectedDetectorUI, (AstigmaticBiplaneCalibrationEstimatorUI) calibrationEstimatorUI, defocusModel, stageStep, zRangeLimit, imp1, imp2, roi1, roi2);
    } else {
        throw new IllegalArgumentException("Unknown instance of astigmatic calibration estimator!");
    }
}