Automated Thresholding

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Automated Thresholding

Broncosbeatall
Hi everybody,

I'm trying to have a macro automatically threshold an image based on the greyscale values. For example, for a given histogram, I want to threshold the upper 5%. How might I go about writing this? I'm rather inexperienced in macros so any help would be greatly appreciated. Thanks in advance!

Thomas Huang
Reply | Threaded
Open this post in threaded view
|

Re: Automated Thresholding

kirill8910
Hello Thomas!

What do you mean by "upper" ?

Because if you need 5 % of max value - you can use getStatistic function like:

getStatistics(area, mean, min, max, std);

threshold = 0.05*max;

setThreshold(0, threshold);

Kirill
Reply | Threaded
Open this post in threaded view
|

Re: Automated Thresholding

kirill8910
and getStatistics extracts these max, mean...values from histogram
Reply | Threaded
Open this post in threaded view
|

Re: Automated Thresholding

Broncosbeatall
Thanks a lot! Sorry if i didn't clarify very well, I wanted the 95th to 100th percentile of values and didn't know what functions could do that. What you gave me helped a lot, all I did instead was do

getStatistics(area, mean, min, max, std);

threshold = 0.95*max;

setThreshold(threshold, 255);

Thank you very much!
Reply | Threaded
Open this post in threaded view
|

Re: Automated Thresholding

Gabriel Landini
On Tuesday 28 Aug 2012 17:41:07 you wrote:
> Thanks a lot! Sorry if i didn't clarify very well, I wanted the 95th to
> 100th percentile of values and didn't know what functions could do that.
> What you gave me helped a lot, all I did instead was do
>
> getStatistics(area, mean, min, max, std);
> threshold = 0.95*max;
> setThreshold(threshold, 255);

That is not the 95th to 100th percentile of the *values*, but of the
*maximum*. Not the same thing.
You probably need to integrate the histogram to see what threshold gives you
the 5% of the values to the maximum.

Cheers,

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html