Corpus Callosum macro from NIHImage conversion

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

Corpus Callosum macro from NIHImage conversion

Carmen Sanchez
Hello-
I'm new to ImageJ and would like to use the old NIHImage corpus callosum macro.  Although I've tried to gain fluency in the ImageJ macro language, I have not yet been able to get the macro to work.  (My most recent error message pertains to running the "DrawthePerpendicularLine" macro.  )

I've read previous posts about using the ImageSXM, but I do not have a mac available to run it.  

Has anyone been successful in converting the Corpus Callosum macro into ImageJ?

Any advice would be greatly appreciated!

I've pasted the macro that I've been working on below.

Thanks,
Carmen

// {
// This is a set of macros for measuring the area of various regions in the corpus collosum in MRI scans. It assumes that the scans are 256x256, that you are using a 19" monitor, that the Undo buffer is set to 600K, and that you have a lot of RAM.

// This is the procedure:

// 1) Open or activate the scan to be analyzed and type Z.
// 2) Draw a base line using the line tool.
// 3) Draw perpendicular lines by typing S or R.
// 4) Draw a perpendicular line at an arbitrary location by clicking
//  on the base line with the line tool and typing A.
// 5) Outline the corpus collosum.
// 6) Threshold by typing B.
// 7) Measure the areas by clicking inside each region with the wand.
// 8) Revert to grayscale by typing G. (Optional)
// 9) Dispose of the 768x768 working window by typing D.
// }

// var  {Global variables}
//  WindowNum:integer;
//  x1,y1,x2,y2,LineWidth:integer;
//  size,angle,dx,dy,pi,theta:real;
//  width,height,dx,dy,i:integer;


// this selects line tool, then you need to draw a line.  The getline gives you coordinates
setTool("line");
getLine(x1, y1, x2, y2, lineWidth);
   if (x1==-1)
      exit("This macro requires a straight line selection");
   else
     getPixelSize(unit, pw, ph);
     x1*=pw; y1*=ph; x2*=pw; y2*=ph;
     print("Starting point: (" + x1 + ", " + y1 + ")");
     print("Ending point: (" + x2 + ", " + y2 + ")");
     print("Width:", lineWidth, "pixels");
     dx = x2-x1; dy = y2-y1;
     length = sqrt(dx*dx+dy*dy);
     print("Length:", length, unit);


macro "DrawPerpendicularLine(x,y)" {
  getLine(x1, y1, x2, y2, lineWidth);
  getLocationAndSize(x,y,width, height);
  moveTo(x1,height-y1);
  lineTo(x1+size*cos(theta+angle),height-(y1+size*sin(theta+angle)));
  moveTo(x1,height-y1);
  lineTo(x1+size*cos(theta-angle),height-(y1+size*sin(theta-angle)));
}


macro "DrawLines(nSegments)" {
  for (i=1; i<nSegments-1; i++) {
    run ("DrawPerpendicularLine"((x1+round(i*dx/nSegments)),y1+round(i*dy/nSegments)));
}


macro "DrawLeftLine" {
  nSegments=5;
  i=1;
  run ("DrawPerpendicularLine"(x1+round(i*dx/nSegments)),y1+round(i*dy/nSegments)));
}

macro "DrawRightLine" {
  nSegments=5;
  i=4;
  run ("DrawPerpendicularLine"(x1+round(i*dx/nSegments)),y1+round(i*dy/nSegments));
}

y1=height-y1;
y2=height-y2;
angle=(angle/180)*PI;
dx=x1-x2;
dy=y1-y2;

macro "DrawThePerpendiculars" {
  getLine(x1,y1,x2,y2,lineWidth);
  getLocationAndSize(x,y,width, height);
  if (dx==0)
      if (dy>=0) {
          theta=PI/2;
      }
      else {
          theta=3/2*PI;
      }
    theta=atan(dy/dx);
    if (dx<0) then theta=theta+pi;
 }
 dx=x2-x1;
 dy=y2-y1;
 SetForegroundColor(255);
  run ("DrawLines(2)");
  run ("DrawLines(3)");

}


macro "Draw Perpendicular Lines-Left[S]" {
  run ("DrawThePerpendiculars");
  run ("DrawLeftLine");
}


macro "Draw Perpendicular Lines-Right[R]" {
  run ("DrawThePerpendiculars");
  run ("DrawRightLine");
}


macro "Draw Arbitrary Perpendicular Line [A]" {
// var
//   xx1,yy1,xx2,yy2:integer;
//  fraction:real;
  if (angle==0) {
    print ("Draw the other perpendiclular lines first");
  }
  if (dx==0) {
   print ("Draw base line first.");
  }
  getLine(xx1,yy1,xx2,yy2,lineWidth);
  if not ((xx1>x1) &&amp; (xx1<x2)) {
    print("Click with the line selection tool first.");
  }
  fraction=(xx1-x1)/dx;
  run ("DrawPerpendicularLine"((x1+round(dx*fraction)),y1+round(dy*fraction));
}


macro "Make Binary [B]" {
  print("Please outline first.");
  doWand(x,y,4.0,8-connected);
  roiManager("Add");
  //run("Threshold...");
  setThreshold(23, 31);
  run("Convert to Mask");
  run("Close-");
  run("Remove Outliers...", "radius=3 threshold=50 which=Dark");
}