ImageJ Automatic QRPDA Code

From WikiEducator
Jump to: navigation, search

The following is the code used to create the macro used by ImageJ to automatically analyze pictures of test strips. (Cadle, 2010)

This code was last updated 4/5/2010.

Written by Andrew Hannum.


Code

makeRectangle('x', 'y', 'width', 'height');

run("Subtract Background...", "rolling=50 light");

run("Select First Lane");
run("Plot Lanes");

doWand('x', 'y');
run("Clear");
run("Analyze Line Graph");
Plot.getValues(x,y);

xlength=x.length;
maxy1=0;
maxx1=0;
for (i=0; i<x.length/2; i++) {
if (y[i] > maxy1) {
maxy1 = y[i];
maxx1 = x[i];
icount1=i;
}
}
maxy2=0;
maxx2=0;
for (i=x.length/2; i<x.length; i++) {
if (y[i] > maxy2) {
maxy2 = y[i];
maxx2 = x[i];
icount2=i;
}
}
close();

plotwidth=getWidth();
bandwidth=50;

x1start=maxx1-bandwidth/2;
x1end=maxx1+bandwidth/2;
x2start=maxx2-bandwidth/2;
x2end=maxx2+bandwidth/2;

y1start=y[icount1-x.length/plotwidth*50];
y1end=y[icount1+x.length/plotwidth*50];
y2start=y[icount2-x.length/plotwidth*50];
y2end=y[icount2+x.length/plotwidth*50];

drawLine(x1start-5, getHeight()-y1start-5, x1end+5, getHeight()-y1end-5);
drawLine(x2start-5, getHeight()-y2start-5, x2end+5, getHeight()-y2end-5);

doWand(maxx1, getHeight()-maxy1+5);
getStatistics(area1);
doWand(maxx2, getHeight()-maxy2+5);
getStatistics(area2);

print("Peak 1 Area:",area1," Peak 2 Area:",area2)
print("Ratio:",area2/area1);
print(error);

if(icount2+x.length/plotwidth*bandwidth > x.length) {
x2end=x2start+1;
y2end=y2start+1;
error="Error: Peak too close to edge";
}

if(icount2+x.length/plotwidth*bandwidth < x.length) {
y2end=y[icount2+x.length/plotwidth*bandwidth];
}