Re: get 3 max and min values

Posted by Michael Schmid on
URL: http://imagej.273.s1.nabble.com/get-3-max-and-min-values-tp3692913p3692915.html

Hi Dani,


There are two ways:

(1) Get the histogram and analyze it. For float images, the accuracy  
will be limited, however.

(2) The "destructive way", with higher accuracy for float images:

First make a copy of your image to work with.

Use getStatistics to get the maximum. Then use the new  
process>Math>Macro command to eliminate the pixel(s) with value=maximum:

run("Macro...", "  code=[if(v>="+myMax+") v="+minValue+";]");
where myMax is the maximum from the statistics (beware of rounding  
error in float numbers converted to a string, so set it to a slightly  
lower value).
minValue=0 for integer images, and -1.79E308 for float images.

Again, repeat for 2nd-highest values (now the previous maximum is not  
a highest value any more), etc.

Michael
________________________________________________________________

On 15 Apr 2009, at 19:48, danibodor wrote:

> I know that you can get the max and min of a selection with the  
> getMinAndMax function (or getStatistics). Is there a way to get  
> e.g. the 3 maximum or minimum values. I was searching for a  
> function to list all the values in a selection, and then sorting  
> those and getting X maximal or minimal values. However, I cannot  
> find a way of listing all the values in my selection. Also, I don't  
> know if it possible to then easily sort them to get the highest  
> values.
>
> Can anyone help me?
>
> Thanks!