All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ij.plugin.XY_Reader Maven / Gradle / Ivy

Go to download

ImageJ is an open source Java image processing program inspired by NIH Image for the Macintosh.

There is a newer version: 1.54m
Show newest version
package ij.plugin;
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.measure.*;
import ij.plugin.TextReader;

/** This plugin implements the File/Import/XY Coordinates command. It reads a
	two column text file, such as those created by File/Save As/XY Coordinates,
	as a polygon ROI. The ROI is displayed in the current image or, if the image
	is too small, in a new blank image.
*/
public class XY_Reader implements PlugIn {

	public void run(String arg) {
		TextReader tr = new TextReader();
		ImageProcessor ip = tr.open();
		if (ip==null)
			return;
		int width = ip.getWidth();
		int height = ip.getHeight();
		if (width!=2 || height<3) {
			IJ.showMessage("XY Reader", "Two column text file required");
			return;
		}
		float[] x = new float[height];
		float[] y = new float[height];
		boolean allIntegers = true;
		double length = 0.0;
		for (int i=0; i0) {
				double dx = x[i] - x[i-1];
				double dy = y[i] - y[i-1];
				length += Math.sqrt(dx*dx+dy*dy);
			}
		}
		Roi roi = null;
		int type = length/x.length>10?Roi.POLYGON:Roi.FREEROI;
		if (allIntegers)
			roi = new PolygonRoi(Roi.toIntR(x), Roi.toIntR(y), height, type);
		else
			roi = new PolygonRoi(x, y, height, type);
		Rectangle r = roi.getBoundingRect();
		ImagePlus imp = WindowManager.getCurrentImage();
		if (imp==null || imp.getWidth()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy