Finding the centre of a ROI with the highest mean pixel intensity



Hi all,

I’m new to ImageJ and was hoping you could help me with this.

I need to create a circular ROI of radius 20 pixels, and find the centre of the circle where the ROI has the highest mean pixel intensity in the image. Any help would be greatly appreciated!


Maybe there is something that works better, but you could write a plugin that creates oval roi and then iterates over the image to find the location with the maximum mean value of the Roi.


Good day!

If you could live with an odd diameter I suggest the following:

  1. Unzip the following file (248 Bytes)
  2. Make sure the image you want to process is open in ImageJ
  3. Go to “Process >> Filters >> Convolve…”
  4. From the Convolve-dialog open the textfile “disc21.txt”
  5. Click OK in the Convolve-dialog
  6. Go to “Process >> Find Maxima…” and increase the tolerance until a single maximum is present.




Here is an ImageJ-macro that does what you want:

// imagej-macro "convolutionMax" (Herbie G., 09. July 2018)
requires( "1.52d" );
d = getNumber("Kernel diameter in pixels", 21);
if (d%2==0) exit("Diameter must be an odd number of pixels!");
newImage("kernel", "8-bit black", d, d, 1);
makeOval(0, 0, d, d);
setForegroundColor(1, 1, 1);
run("Fill", "slice");
path = getDirectory("temp")+"kernel.txt";
saveAs("Text Image", path);
run("Convolve...", "text1=["+File.openAsString(path)+"] normalize");
getRawStatistics(N, mn, mi, mx);
run("Find Maxima...", "noise="+(mx-mi)+" output=[Point Selection]");

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it. (The image you like to analyze must be open in ImageJ before you run the macro.)


Thank you so much, this is perfect!