Posted by
Michael Schmid on
Apr 28, 2011; 12:01pm
URL: http://imagej.273.s1.nabble.com/how-to-count-the-number-of-peaks-in-a-dynamic-profile-tp3684809p3684810.html
Hi Paul,
for finding whether a point is a maximum it is not enough to check
whether a profile along the x direction has a maximum. It must be
also a maximum in the y direction (and in the diagonal directions,
when considering 8-connected pixels).
Also, you may have a maximum with several pixels of the same value,
which would be lost in your approach.
So, I'd recommend ImageStatistics for finding the overall maximum
(this is much faster than the macro approach) and Process>Find Maxima
for finding local maxima. "Find Maxima" also has an option to limit
maximum finding to values above the lower threshold of a thresholded
image - just threshold your image between 90% of the overall maximum
and the full maximum.
Michael
________________________________________________________________
On 28 Apr 2011, at 11:19, paul_rostand wrote:
> Hello imagej users,
>
> I am trying to count and locate the peaks in a picture.for this
> purpose I use
> the following macro wich is an adaptation of the
> FindMaxPixelLocation macro. for
> peak identification I just compare the values of consecutives points
> (curve[i+1]) && (curve[i+1]>curve[i+2])
>
> curve[i] being the pixel value at location i of the loop. but as
> result I get 39
> peaks instead of 4 (see the attached profile)
>
> I would like to know what I am doing wrong and if anyone has
> another easier way
> to solve this problem
> thanks in advance
> regards
>
> Paul Rostand
>
> showStatus("Finging pixel with largest value...");
> max = 0;
> peak=0;
> width = getWidth();
> height = getHeight();
> for (y=0; y<height; y++) {
> if (y%20==0) showProgress(y, height);
> for (x=0; x<50; x++) {
> value = getPixel(x,y);
> if (value>max) {
> max = value;
> xmax = x;
> ymax = y;
> }
> }
> }
> print("A pixel with the max value ("+max+") is located at "+xmax
> +","+ymax);
>
> curve=newArray(width);
> threshold = 0.9*max; // define the threshold
> used to count
> the peaks
>
> for (y=0; y<height; y++) {
> if (y%20==0) showProgress(y, height);
> for (x=0; x<50; x++) {
> value = getPixel(x,y);
> if (value>threshold) {
> for (i=0;i<48;i++) {
> curve[i]=value;
> if((curve[i]<curve[i+1]) && (curve[i+1]>curve[i+2])){
> peak=peak+1;
> }
> }
> }
> }
> }
> print("the number of peaks is "+peak+");
>
> --
> View this message in context:
http://imagej.588099.n2.nabble.com/
> how-to-count-the-number-of-peaks-in-a-dynamic-profile-
> tp6312558p6312558.html
> Sent from the ImageJ mailing list archive at Nabble.com.