Over the years I have written a lot of versions of macros to overlay or draw grids or other patterns on images. One is below which was designed for setting a template for photoablation.

However, for more common applications, such as stereology, Fiji comes bundled with a versatile plugin for overlaying patterns.
Analyze > Tools > Grid...
which can used in macros, such as
run("Grid...", "grid=Lines area=30 color=Cyan random");



Macro to draw a pattern of grid.

Designed for squares or circles.

Examples results:

Note that the title of each image reports the spacing, center to center, of the black spots, the width of each black square, and the number of squares on each side.

Macro here bundled with other macros and here:

/*  Draws a pattern at the center of an image.  Works better with even numbers.
    Finds the upper left corner and then draws the spots from there.
macro "grid pattern" {
  spacing = 36;         // center to center spacing
  diameter = 8;         // width of the square or circle
  numberSpots = 10;     // number of spots in each X and Y
  title = "spacing_" + spacing + " diameter_" + diameter + " numberSpots_" + numberSpots;
  newImage(title, "8-bit white", 512, 512, 1);  // make an image any size you want
  xc = getWidth/2;
  yc = getHeight/2;
  startX = xc  - (numberSpots*spacing/2) - diameter/2 - spacing/2;
  startY = yc  - (numberSpots*spacing/2) - diameter/2 - spacing/2;
  for (ys=1; ys<=numberSpots; ys++) 
    for (xs=1; xs<=numberSpots; xs++) {  
      makeRectangle(startX+xs*spacing-diameter/2, startY+ys*spacing-diameter/2, diameter, diameter);
      run("Set...", "value=0");
  run("Select None");


This should be modified to be a function with arguments for varied spacing, diameter, and number spots. And could get fancier with circles or squares, colors, etc. And overlaid or drawn into image.


macro last updated 20191003_1000
web page last updated Feb 2023