# [ImageJ] Extract cell coordinates of the maximum value of items in set measurements

Hello. My name is Kuroishi. Today I would like to know about the problems I am currently having.

Currently, I would like to use ImageJ to analyze using macros.
At that time, I would like to extract the coordinates by finding the maximum value of the vertical axis by the item (eg area or average) of the particle analysis result. Assign the extracted value to any variable to use. I think that can not be done with Table.get etc, but I do not think about a good solution.

We apologize for being a very abstract question.

Hi Kuroishi,

My interpretation of your question is:

Given an roi and a Z-stack, assign the roi a Z-coordinate based off which slice has the highest average intensity.

This is easier through scripting (Jython in this example) but this would also be possible in macro as well. The solution comes from this post.

``````# set the roi
imp.setRoi(roi)

# plot the Z-axis profile and get the intensities
from ij.plugin import ZAxisProfiler
plot = ZAxisProfiler.getPlot(imp)
ints = [v+0. for v in plot.getYValues() ]	 # convert the double for max finder

# find the maximum
from ij.plugin.filter import MaximumFinder
maxs = MaximumFinder.findMaxima(ints, 1. ,False)
if( len(maxs)>0 ):
z=maxs[0]

``````

The macro approach would involve the same steps but need for juggling of windows, let me know if you’d a translation.

Cheers,

Chris

What I am currently thinking about is as follows.

``````run("Set Measurements...", "area mean centroid display redirect=None decimal=6");
run("Analyze Particles...", "  show=Outlines display clear");
column6Name = "X"; // adjust as needed
column7Name = "Y";
rowIndex = 0;

a = Table.get(column6Name, rowIndex);
b = Table.get(column7Name, rowIndex);
r=Table.getColumn(column6Name);
t=Table.getColumn(column7Name);
r=eval("js", "r.indexOf(Math.max.apply(null,r))");
t=eval("js", "t.indexOf(Math.max.apply(null,t))");
``````

However, this will cause an error if it is not recognized in the js code.
Is there no solution?
Thank you.

Hi,

thanks for the clarification - no Z involved. It looks like you’re in the macro language so you can use the `Array` functions to find the maxima and minima (see this page here for a full list of macro functions):

``````// Get the columns from the active Results table
X=Table.getColumn("X");
Y=Table.getColumn("Y");

// locate maxima in the array, returns an array
indices_max = Array.findMaxima(Y, 1);
imax = indices_max[0] // just keep the largest

print(imax,Y[imax])
``````

The columns “X” and “Y” will give you the coordinates of the centroid of the roi. If you want the extremes of roi you can use the “BY” and “BY” and “Width” and “Height” instead. Careful of the Y coordinates, the origin is at the top.

Cheers,

Chris

Thank you for answering many times.
I want to extract the array number (box number) containing the maximum value, not the maximum value.
I am very sorry for the explanation, but I would like to know.
Thank you.

In the above imax is the row of column that corresponds to the maximum.

I must sincerely apologize. The problem was solved! Thank you for your cooperation!