ROI Iterator Demo

Authors: Wilhelm Burger and Wayne Rasband
History: 2016/04/15: First version
Requires: ImageJ 1.51a or later
Installation: Save 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 =;
  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:

  newImage("Contained Points","8-bit black",getWidth,getHeight,1);
  for (i=0; i<x.length; i++)
     putPixel(x[i], y[i], 255);
Test image: Shapes.tif