Login  Register

Re: automatic threshold value

Posted by Michael Schmid on Aug 08, 2007; 6:53pm
URL: http://imagej.273.s1.nabble.com/automatic-threshold-value-tp3698659p3698662.html

Hi,

Sorry, a correction:

It should be

   double threshold =
       min + thresholdInt/(double)(histogram.length-1)*(max-min);

(mind the "minus 1")

For histograms that come from ImageStatistics, the length is
always 256 (irrespective of image type), so the code simplifies
to
     double threshold = min + thresholdInt/255.0*(max-min);

min and max also come from ImageStatistics.


Michael
________________________________________________________________

On 8 Aug 2007, at 17:18, Michael Schmid wrote:

> Hi Paxton,
>
> in a plugin you can use
>   int thresholdInt = ip.getAutoThreshold(int[] histogram);
> with the histogram obtained from ImageStatistics.
> You will get which index of the histogram that the threshold
> corresponds to - for uncalibrated 8-bit images this is the
> threshold; otherwise conversion is necessary - I guess
> something like the following:
>   double threshold = min + thresholdInt/(double)histogram.length*
> (max-min);
>
> You won't get whether the thresholded (red) pixels will be
> above or below the threshold.
> Strange enough, the code for this decision (and also for
> conversion of histogram index to a float value) is not public
> in ImageJ and also duplicate (but slightly different) in
> Functions.java and ThresholdAdjuster.java
>
>
> Michael
> ________________________________________________________________
>
> On 8 Aug 2007, at 16:32, Paxton Provitera wrote:
>
>> Hi.
>> How does the Image>Adjust>Threshold... function determine the  
>> value at which
>> it assigns the threshold limit, and how can I access that value in  
>> a plugin?
>>
>> Thanks for your help.
>>
>> -Paxton