import ij.plugin.filter.*; import java.awt.*; import java.awt.image.*; import java.util.Vector; import java.io.*; import ij.*; import ij.process.*; import ij.io.*; import ij.gui.*; import ij.measure.*; /** Saves evenly spaced (one pixel) X-Y coordinates along the current ROI boundary. */ public class Path_Writer implements PlugInFilter, Measurements { ImagePlus imp; double[] xpath; double[] ypath; int pathLength; int arrayLength; boolean invertYCoordinates; public int setup(String arg, ImagePlus imp) { this.imp = imp; return DOES_ALL+ROI_REQUIRED+NO_CHANGES; } public void run(ImageProcessor ip) { try { saveXYCoordinates(imp); } catch (IllegalArgumentException e) { IJ.showMessage("Path Writer", e.getMessage()); } } public void saveXYCoordinates(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi==null) throw new IllegalArgumentException("ROI required"); if (!(roi instanceof PolygonRoi)) throw new IllegalArgumentException("Irregular area or line selection required"); SaveDialog sd = new SaveDialog("Save Coordinates as Text...", imp.getTitle(), ".txt"); String name = sd.getFileName(); if (name == null) return; String directory = sd.getDirectory(); PrintWriter pw = null; try { FileOutputStream fos = new FileOutputStream(directory+name); BufferedOutputStream bos = new BufferedOutputStream(fos); pw = new PrintWriter(bos); } catch (IOException e) { IJ.showMessage("XYWriter", ""+e); return; } PolygonRoi p = (PolygonRoi)roi; getPath(p); //drawPath(imp); Calibration cal = imp.getCalibration(); String ls = System.getProperty("line.separator"); boolean scaled = cal.scaled(); int maxy = imp.getHeight()-1; double w = cal.pixelWidth; double h = cal.pixelHeight; int digits = roi.getType()==Roi.TRACED_ROI&&w==1.0&&h==1.0?0:4; int measurements = Analyzer.getMeasurements(); invertYCoordinates = (measurements&INVERT_Y)!=0; if (invertYCoordinates) { for (int i=0; i