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

The following examples show how to use ij.gui.Roi#getBoundingRect() . 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: Stitching_2D.java    From Stitching with GNU General Public License v2.0 5 votes vote down vote up
private Point2D getImageOffset(CrossCorrelationResult2D result, ImagePlus imp1, ImagePlus imp2)
{
	// see "ROI shift to Image Shift.ppt" for details of nomenclature
	Point2D 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 Point2D(x1, y1);
		r2 = new Point2D(x2, y2);

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

	return si;
}
 
Example 2
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 3
Source File: Stitching_2D.java    From Stitching with GNU General Public License v2.0 4 votes vote down vote up
private FloatArray2D applyROI(ImagePlus imp, Point2D imgDim, Point2D extDim, String handleRGB, boolean windowing)
{
	FloatArray2D img;

	if (imp.getRoi() == null)
	{
		// there are no rois....
		img = ImageToFloatArray(imp.getProcessor(), handleRGB);
	}
	else
	{
		Roi r = imp.getRoi();

		int x = r.getBoundingRect().x;
		int y = r.getBoundingRect().y;
		int w = r.getBoundingRect().width;
		int h = r.getBoundingRect().height;

		img = ImageToFloatArray(imp.getProcessor(), handleRGB, x, y, w, h);
	}

	imgDim.x = img.width;
	imgDim.y = img.height;

	extDim.x = extDim.y = 0;

	if (windowing)
	{
		int imgW = img.width;
		int imgH = img.height;
		int extW = imgW / 4;
		int extH = imgH / 4;

		// add an even number so that both sides extend equally
		if (extW % 2 != 0) extW++;
		if (extH % 2 != 0) extH++;

		extDim.x = extW;
		extDim.y = extH;

		imgDim.x += extDim.x;
		imgDim.y += extDim.y;

		// extend images
		img = extendImageMirror(img, imgW + extW, imgH + extH);
	}

	return img;
}
 
Example 4
Source File: Stitching_3D.java    From Stitching with GNU General Public License v2.0 4 votes vote down vote up
private FloatArray3D applyROI(ImagePlus imp, Point3D imgDim, Point3D extDim, String handleRGB, boolean windowing)
{
	FloatArray3D stack;

	if (imp.getRoi() == null)
	{
		// there are no rois....
		stack = StackToFloatArray(imp.getStack(), handleRGB);
	}
	else
	{
		Roi r = imp.getRoi();

		int x = r.getBoundingRect().x;
		int y = r.getBoundingRect().y;
		int w = r.getBoundingRect().width;
		int h = r.getBoundingRect().height;

		stack = StackToFloatArray(imp.getStack(), handleRGB, x, y, w, h);
	}

	imgDim.x = stack.width;
	imgDim.y = stack.height;
	imgDim.z = stack.depth;

	extDim.x = extDim.y = extDim.z = 0;

	if (windowing)
	{
		int imgW = stack.width;
		int imgH = stack.height;
		int imgD = stack.depth;
		int extW = imgW / 4;
		int extH = imgH / 4;
		int extD = imgD / 4;

		// add an even number so that both sides extend equally
		if (extW % 2 != 0) extW++;
		if (extH % 2 != 0) extH++;
		if (extD % 2 != 0) extD++;

		extDim.x = extW;
		extDim.y = extH;
		extDim.z = extD;

		imgDim.x += extDim.x;
		imgDim.y += extDim.y;
		imgDim.z += extDim.z;

		// extend images
		stack = extendImageMirror(stack, imgW + extW, imgH + extH, imgD + extD);
	}
	return stack;
}