Find x value of profile maximum or array

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

Find x value of profile maximum or array

johnyg
Hi,
I need to find the x value that corresponds to the maximum intensity value
of a line profile in an image. So far I can find the maximum using
Array.getStatistics, but I don't know how to find the corresponding x value
(x value is the distance from the start of the profile).
 
So far I have this...
 
makeLine(192, 0, 192, 15/Resolution);  
 
profile0 = getProfile();
for (i=0; i<profile0.length-1; i++)
setResult("PxlVal0", i, profile0[i]);
updateResults;
 
Array.getStatistics(profile0,max);
print(max);
 
Any help would be greatly appreciated.
Reply | Threaded
Open this post in threaded view
|

Re: Find x value of profile maximum or array

johnyg
I have found something similar but in another programming language, but I don't have a clue how to translate it into imagej language

http://proto.layer51.com/d.aspx?f=254

To recap: I draw a short line profile, and want to find the position of the max and return it as a variable to my code
Reply | Threaded
Open this post in threaded view
|

Re: Find x value of profile maximum or array

johnyg
In reply to this post by johnyg
I found a solution so thought I would post it for everyone...

profile1 = getProfile();

Array.getStatistics(profile1,min,max);

A = indexOfArray(profile1, max);

And the associated function....

//Returns the indices at which a value occurs within an array
function indexOfArray(array, value) {
    count=0;
    for (i=0; i<lengthOf(array); i++) {
        if (array[i]==value) {
            count++;
        }
    }
    if (count>0) {
        indices=newArray(count);
        count=0;
        for (i=0; i<lengthOf(array); i++) {
            if (array[i]==value) {
                indices[count]=i;
                count++;
            }
        }
        return indices;

print(indices);
    }