Authors: Wilhelm Burger and Wayne Rasband
History: 2016/04/15: First version
Source: Roi_Iterator_Demo.java Requires: ImageJ 1.51a or later Installation: Save Roi_Iterator_Demo.java in the ImageJ/plugins folder and compile and run it using the Plugins>Compile and Run command. Description: This plugin demonstrates how to iterate over the points contained in a selection. What it does is generate a binary image of all points included in the current overlay or selection. JavaScript does not support Java's enhanced for loop so you must use an explicit iterator loop, for example:
img = IJ.getImage(); ip = new ByteProcessor(img.getWidth(),img.getHeight()); roi = img.getRoi(); iter = roi.iterator(); while (iter.hasNext()) { p = iter.next(); ip.set(p.x,p.y,255); } new ImagePlus("Contained Points",ip).show();In a macro, use the getContainedPoints(x,y) function to iterate over the points in a selection, for example:
Roi.getContainedPoints(x,y); newImage("Contained Points","8-bit black",getWidth,getHeight,1); setColor(255); for (i=0; i<x.length; i++) putPixel(x[i], y[i], 255);Test image: Shapes.tif