Posted by
Pang, Zhengyu (GE Global Research) on
Jun 11, 2009; 7:47pm
URL: http://imagej.273.s1.nabble.com/Percentile-value-tp3690983p3690986.html
Hi all,
To get the percentile value, I think that I could get all the pixel
value by using getpixel (I,j) and make an array.
Then I need to sort the array. How do I sort the array using ImageJ
macro language? Do you have to make a function?
Thanks!
Zhengyu
-----Original Message-----
From: ImageJ Interest Group [mailto:
[hidden email]] On Behalf Of
Pang, Zhengyu (GE, Research)
Sent: Thursday, June 11, 2009 10:15 AM
To:
[hidden email]
Subject: Re: Percentile value
Ben,
Thanks for your help. I tested your macro and it worked. As you said,
this is only an approximation.
I am wondering if ImageJ could read an image and then convert image to a
matrix like what Matlab can do. Could you then sort the matrix and found
5% percentile?
Best Regards,
Zhengyu
-----Original Message-----
From: ImageJ Interest Group [mailto:
[hidden email]] On Behalf Of
Ben Tupper
Sent: Wednesday, June 10, 2009 8:34 PM
To:
[hidden email]
Subject: Re: Percentile value
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