How to find the position of a number within an array based on some property

Hi all,

this is a very basic question from a beginner.

I am analyzing a stack to get the integrated density for each slice and am placing the results in the “results” table.
What I need to do now is to find which slice has the maximum integrated intensity value so that I can continue with my workflow.

I am not seeing a straightforward way of doing what seems to be a rather easy thing to do - so my guess is that I am probably overlooking something. Need help!

So far, the only thing I can think of is:

  1. to create two arrays, one that stores the slice numbers, and another that stores the measured property for each slice.
  2. Then, find the maximum within second array.
  3. Use an If/else statement to go through that second array one position at a time, until it finds the maximum value.
  4. When there is a match get the position of the slice.

One can consider to do this without generating a slice array, but I still find this very complicated for something that appears very basic. Can anyone say if there is a more elegant way to do this?

Best,
R.

Hi @rhjpires,

A few follow up questions to help you get more focused answers:

  1. Is this an imageJ question?
  2. What language are you coding in?
  3. Are you open to solutions in any programming language?

John

Hi there,

sorry sorry, totally forgot to mention those.

Yes, I am writing a script in imageJ Macro language and I am not versed in much else, other than programming in Igor Pro which I mostly use to look at 1D and 2D data. I’m a novice when it comes to imageJ. Having said that, I am open to other programming languages especially if that means python.

In the meantime I am working with ImageJ macro language and for this problem I am making an array with all the integrated intensities for each slice and getting the maximum from that array. Then going back to that array and check where the maximum is. It just seems to be quite cumbersome, and I was hoping that i could do it more elegantly. Let me know if there is a better way.

Best,
R.

1 Like

Would the function Array.findMaxima(array, tolerance) fit better your need? It returns an array of indices, the first pointing to the element with the maximum value.

Giovanni

Hi there,

Array.findMaxima(array, tolerance) is indeed helpful!!
Many thanks!
R.