Back to photostream

example

//Macro for ImageJ by

//Michael Cammer cammer@aecom.yu.edu for AIF www.aecom.yu.edu/aif/

//Data presented or published using this/these macro(s)/function(s) or modification(s) thereof

//must acknowledge the "Analytical Imaging Facility at the Albert Einstein College of Medicine"

//and ImageJ as explained at rsb.info.nih.gov/ij/docs/faqs.html

 

// revision 1.02 July 11, 2005

// This macro finds the area of the traced object.

// Assuming this area is of a perfect circle, the radius is calculated.

// Then the difference between the circle's radius and the real radii are calculated.

// This version measures the number of radii, evenly spaced, specified by variable n.

// All radii are normalized by a factor such that the standard radius is always 100.

 

macro"Radial Sweep [q]"{

requires('1.34k');

n = 256;

run("Set Scale...", "distance=1 known=1 pixel=1 unit= global");

run("Set Measurements...", " centroid area redirect=None decimal=0");

run("Measure");

xc = getResult("X", nResults-1);

yc = getResult("Y", nResults-1);

A = getResult("Area", nResults-1);

selectWindow("Results");

run("Close");

r = sqrt(A/3.1415);

factor = 100 / r;

r = r * factor;

 

// This routine gets all the pixels along a ROI, not just vertices.

// It only works with the magic wand tool or a complete freehand ROI tool.

// It does not work with the polygon tool!

getSelectionCoordinates(x_, y_);

x = newArray(x_.length+1);

y = newArray(x_.length+1);

for (i=0; i<x_.length; i++){

x[i] = x_[i];

y[i] = y_[i];

}

x[x_.length] = x_[0];

y[y_.length] = y_[0];

newx = newArray(65535);

newy = newArray(65535);

newindex = 0;

for (i=0; i<x.length; i++){

if (i 0) step = 1; else step = -1;

for (k=y0; k!=y1; k=k+step) {

newx[newindex] = x[i];

newy[newindex] = k;

newindex++;

} // for k

} // if (x[i+1] == x[i])

if (y[i+1] == y[i]){

x0 = x[i];

x1 = x[i+1];

dx = x1 - x0;

if (dx > 0) step = 1; else step = -1;

for (k=x0; k!=x1; k=k+step) {

newx[newindex] = k;

newy[newindex] = y[i];

newindex++;

} // for k

} // if (y[i+1] == y[i])

if ( (x[i] != x[i+1]) && (y[i]!=y[i+1]) ){

newx[newindex] = x[i];

newy[newindex] = y[i];

newindex++; }

} // if (i < (x.length-1))

} // for i

// This is the end of the routine that gets the coordinates along the edge.

// The coordinates are stored in the arrays x and y.

 

 

//setBatchMode(true);

 

stepsize = floor(newindex/n); //stepsize = 1;

print('//************************'); print(getTitle());

difference = newArray(65535);

newindex = newindex - 1;

sum = 0; count = 0;

for (i=0; i<newindex; i=i+stepsize) {

dx = xc - newx[i];

dy = yc - newy[i];

diag = factor * (sqrt ( (dx*dx) + (dy*dy) ));

//print(diag-r);

difference[count] = diag-r;

sum = sum + (diag-r); count++;

}

average = sum /count;

print("area", A);

print("average", average);

dif = newArray(count);

for(i=0;i 1){

variance = calculateUnbiasedVariance(a);

print("variance", variance);

stdev = pow(variance, 0.5);

print("stdev", stdev);

return stdev;}

else

return 0;

}

 

//----------------------------------------------------------------------------------

//Calculates BIASED variance as defined at davidmlane.com/hyperstat/A16252.html

//It is biased because it tends to underestimate the spread.

//We, however, like to err on the side of caution, a.k.a. UNBIASED.

//The variance is a measure of how spread out a distribution is.

//It is computed as the average squared deviation of each number from its mean.

//Function is passed an array of numbers and returns a single number.

function calculateBiasedVariance(a){

//get the mean

sum = 0;

for (i=0;i<a.length;i++) sum = sum + a[i];

mean = sum / a.length;

//get the top of the equation

sum2 = 0;

for (i=0;i 1){

//get the mean

sum = 0;

for (i=0;i<a.length;i++) sum = sum + a[i];

mean = sum / a.length;

//get the top of the equation

sum2 = 0;

for (i=0;i0) {

stdDev = (n*sum2-sum*sum)/n;

if (stdDev>0.0)

stdDev = Math.sqrt(stdDev/(n-1.0));

else

stdDev = 0.0;

}

else

stdDev = 0.0;

}

153 views
0 faves
0 comments
Uploaded on October 26, 2008