Re: Percentile value
Posted by BenTupper on
URL: http://imagej.273.s1.nabble.com/Percentile-value-tp3690983p3690984.html
Hi,
On Jun 9, 2009, at 11:19 AM, Pang, Zhengyu (GE, Research) wrote:
> Dear all,
>
> ImageJ could provide you with Mean, median, min and max. How do I
> get 1
> percentile, or 5 percentile values? And how do I get the average for
> first percentile.?
>
I Wonder if the cumulative histogram (normalized) could work for you.
The following converts the histogram to a cumulative histogram, then
normalizes it to the number of pixels in the image. I'm no stats
guy, so this might be considered an approximation by purists.
Cheers,
Ben
//START MACRO
//run("Blobs (25K)");
nBins = 256;
getHistogram(values, counts, 256);
//create a cumulative histogram
cumHist = newArray(nBins);
cumHist[0] = values[counts[0]];
for (i = 1; i < nBins; i++){ cumHist[i] = counts[i] + cumHist[i-1]; }
//normalize the cumulative histogram
normCumHist = newArray(nBins);
for (i = 0; i < nBins; i++){ normCumHist[i] = cumHist[i]/
cumHist[nBins-1]; }
// find the 5th percentile (= 0.05)
target = 0.05;
i = 0;
do {
i = i + 1;
print("i=" + i + " value=" + values[i] + " count=" + counts[i] + "
cumHist= " + cumHist[i] + " normCumHist= " + normCumHist[i] );
} while (normCumHist[i] < target)
print("5th percentile located at either " + (i-1) + "th or " + (i) +
"th bin");
print(" which has a location of " + values[i-1] +" or " + values[i]);
//END MACRO
Ben Tupper