Login  Register

Re: Area fraction within multiple ROIs

Posted by lindaP on Mar 18, 2014; 8:09pm
URL: http://imagej.273.s1.nabble.com/Area-fraction-within-multiple-ROIs-tp5006915p5006979.html

Hi Ved,

Thanks a lot for offering your solution. I'm trying to understand the script. FYI, I added my interpretation of your code as comments (see below).

The only part where I'm struggling is figuring out what happens during the double for loop. I don't understand the if(i !=j) condition. It seems to me that i always equals to j. Could you give me a hint on that?

Thanks!

Linda  

// ---------  Macro starts here
n =  roiManager("count");   // number of ROIs
areaParticles = newArray(n); // initialization of new arrays with the length corresponding to the number or ROIs
nameParticles = newArray(n);

// This part is completed before the next for loop is evaluated
for(i=0; i<n; i++) {
        roiManager("Select", i);   // selects ith roi
        getStatistics(areaParticles[i]); // Get statistics on ith roi.
                                                        // What happens with the data (area, mean...) received from this call?
                                                        // They don't seem to be stored anywhere.
        nameParticles[i] = Roi.getName; // saves the name of ith ROI in nameParticles array
}

// I understand this part
fraction = newArray(n);
for(i=0; i<n; i++)
        fraction[i] = 0; // initialize fraction array


for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
 // This is when I get confused:
                if(j != i) {    // When does this occur? During the first looping i=0 and j=0 or not?
                        roiManager("Select", newArray(i,j)); // selects two ROIs
                        roiManager("AND"); // calculates intersection of these ROIs
                        getStatistics(area); // measures area of the intersection
                        if(area == areaParticles[i]) // if this is true it means that the first ROI is encapsulated by the second one
                                                                  // or it is the same ROI
                                fraction[i] = (100*areaParticles[i])/areaParticles[j]; //calculates fraction
                }
        }
}
for(i=0; i<n; i++) {
        if(fraction[i] > 0) // excludes fraction calculated by dividing the same ROIs
                print(nameParticles[i]+": area = "+areaParticles[i]+", fraction = "+fraction[i]); //prints out result
}
// ---------  Macro ends here

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