Converting NIH image Macros to the ImageJ ones

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

Converting NIH image Macros to the ImageJ ones

soly
Dear ImageJ users,

I have found two macros called "Circle Grid" and "Random Lines"   in a
Stereology book ( by J. C. Russ ) which are written in NIH image macro
language. I tried to follow the commands and repeat them in ImageJ via
macro record but  no success sofar! Is any of you able to convert such a
Macro to ImageJ macro or plugin so that it can be used in ImageJ? Thank
you.

Best Regards,

Ali


Macro 'Circle Grid';
var
i,j,x,y,xoff,yoff,pwd,pht,nrow,ncol: integer;
len,area,ppx,pi: real;
un: string;
Begin
GetPicSize(pwd,pht);
SetLineWidth(1);
pi:=3.14159265;
nrow:=pht Div 120;
ncol:=pwd Div 120;
xoff:=(pwd - 130*ncol) Div 2;
yoff:=(pht - 130*nrow) Div 2;
For j:=1 To nrow Do
Begin
y:= yoff + 15 + (j-1)*130;
For i:=1 To ncol Do
Begin
x:= xoff + 15 + (i-1)*130;
MakeOvalRoi(x,y,101,101);
DrawBoundary;
KillRoi;
End;
End;
GetScale(ppx,un);
 Len:=nrow*ncol*pi*100/ppx;
MoveTo (2,pht-6);
SetFont('Geneva');
SetFontSize(10);
Write('Total Length=',Len:10:4,' ',un);
area:=pwd*pht/(ppx*ppx);
MoveTo (2,pht-18);
Write('Total Area=',area:10:3,' sq.',un);
End;

----------------------------------
Macro 'Random Lines';

Var
i,j,k,x1,x2,y1,y2,pwd,pht,len,limt: integer;
x,y,theta,m,area,ppx,dummy: real;
un: string;
Begin
GetPicSize(pwd,pht);
len:=0;
k:=0;
limt:=3*(pwd+pht); {minimum total length in pixels}
Repeat {Until length>limt}
x:=Random*pwd;
y:=Random*pht;
theta:=Random*3.14159265;
m:=Sin(theta)/Cos(theta);
x1:=0;
y1:=y+m*(x1-x);
If (y1<0) Then
Begin
y1:=0;
x1:=x+(y1-y)/m;
End;
If (y1>pht) Then
Begin
y1:=pht;
x1:=x+(y1-y)/m;
End;
x2:=pwd;
y2:=y+m*(x2-x);
If (y2<0) Then
Begin
y2:=0;
x2:=x+(y2-y)/m;
End;
If (y2>pht) Then
Begin
y2:=pht;
x2:=x+(y2-y)/m;
End;
MoveTo(x1,y1);
LineTo(x2,y2);
len:=len+Sqrt((x2-x1)*(x2-x1)+(y1-y2)*(y1-y2))
k:=k+1;
Until (len>limt);
GetScale(ppx,un);
area:=pwd*pht/(ppx*ppx);
SetFont('Geneva');
SetFontSize(10);
MoveTo (2,pht-18);
Write('Total Area=',area:10:3,'sq.',un);
len:=len/ppx;
MoveTo (2,pht-6);
Write('Total Length=',len:10:3,' ',un);
End;

--------------------

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Converting NIH image Macros to the ImageJ ones

Cammer, Michael
I think this works up to the GetScale command where I stopped.  Maybe someone else will have a few minutes to finish this; I have to get back to the laser aligning part of my job.  Also, setting the colors would be a good thing to add.
Regards,
Michael

macro "Circle Grid" {
  pwd = getWidth();
  pht = getHeight();
  setLineWidth(1);
  nrow = pht / 120;
  ncol =pwd / 120;
  xoff = (pwd - 130 * ncol) / 2;
  yoff = (pht - 130 * nrow) / 2;
  for (j=1; j<nrow; j++)  {
    y = yoff + 15 + (j-1)*130;
    for (i=1; i<ncol; i++) {
      x = xoff + 15 + (i-1)*130;
      makeOval(x,y,101,101);
      run("Draw");
      run("Select None");
    }  // i
  }  // j

  GetScale(ppx,un);
  Len = nrow * ncol * pi * 100 / ppx;
  MoveTo (2,pht-6);
  SetFont('Geneva');
  SetFontSize(10);
  Write('Total Length=',Len:10:4,' ',un);
  area:=pwd*pht/(ppx*ppx);
  MoveTo (2,pht-18);
  Write('Total Area=',area:10:3,' sq.',un);

} // end

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Ali Soleimani
Sent: Friday, March 15, 2013 10:40 AM
To: [hidden email]
Subject: Converting NIH image Macros to the ImageJ ones

Dear ImageJ users,

I have found two macros called "Circle Grid" and "Random Lines"   in a
Stereology book ( by J. C. Russ ) which are written in NIH image macro language. I tried to follow the commands and repeat them in ImageJ via macro record but  no success sofar! Is any of you able to convert such a Macro to ImageJ macro or plugin so that it can be used in ImageJ? Thank you.

Best Regards,

Ali


Macro 'Circle Grid';
var
i,j,x,y,xoff,yoff,pwd,pht,nrow,ncol: integer;
len,area,ppx,pi: real;
un: string;
Begin
GetPicSize(pwd,pht);
SetLineWidth(1);
pi:=3.14159265;
nrow:=pht Div 120;
ncol:=pwd Div 120;
xoff:=(pwd - 130*ncol) Div 2;
yoff:=(pht - 130*nrow) Div 2;
For j:=1 To nrow Do
Begin
y:= yoff + 15 + (j-1)*130;
For i:=1 To ncol Do
Begin
x:= xoff + 15 + (i-1)*130;
MakeOvalRoi(x,y,101,101);
DrawBoundary;
KillRoi;
End;
End;
GetScale(ppx,un);
 Len:=nrow*ncol*pi*100/ppx;
MoveTo (2,pht-6);
SetFont('Geneva');
SetFontSize(10);
Write('Total Length=',Len:10:4,' ',un);
area:=pwd*pht/(ppx*ppx);
MoveTo (2,pht-18);
Write('Total Area=',area:10:3,' sq.',un); End;

----------------------------------
Macro 'Random Lines';

Var
i,j,k,x1,x2,y1,y2,pwd,pht,len,limt: integer;
x,y,theta,m,area,ppx,dummy: real;
un: string;
Begin
GetPicSize(pwd,pht);
len:=0;
k:=0;
limt:=3*(pwd+pht); {minimum total length in pixels} Repeat {Until length>limt} x:=Random*pwd; y:=Random*pht; theta:=Random*3.14159265; m:=Sin(theta)/Cos(theta); x1:=0; y1:=y+m*(x1-x); If (y1<0) Then Begin y1:=0; x1:=x+(y1-y)/m; End; If (y1>pht) Then Begin y1:=pht; x1:=x+(y1-y)/m; End; x2:=pwd; y2:=y+m*(x2-x); If (y2<0) Then Begin y2:=0; x2:=x+(y2-y)/m; End; If (y2>pht) Then Begin y2:=pht; x2:=x+(y2-y)/m; End; MoveTo(x1,y1); LineTo(x2,y2);
len:=len+Sqrt((x2-x1)*(x2-x1)+(y1-y2)*(y1-y2))
k:=k+1;
Until (len>limt);
GetScale(ppx,un);
area:=pwd*pht/(ppx*ppx);
SetFont('Geneva');
SetFontSize(10);
MoveTo (2,pht-18);
Write('Total Area=',area:10:3,'sq.',un); len:=len/ppx; MoveTo (2,pht-6); Write('Total Length=',len:10:3,' ',un); End;

--------------------

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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Converting NIH image Macros to the ImageJ ones

George Patterson-3
In followup to Michael's submission.
These have not been tested on the same images and compared to the NIH Image macro outputs.



macro "Circle Grid" {
//If images are RGB, use the color picker Image>Color>Color picker... to set the color of ovals or lines and text
//If images are grayscale, ovals, lines, and text will be set to either black or white in the appropriate place below
 pwd = getWidth();
 pht = getHeight();
 setLineWidth(1);
 nrow = pht / 120;
 ncol =pwd / 120;
 xoff = (pwd - 130 * ncol) / 2;
 yoff = (pht - 130 * nrow) / 2;
 ImageType=bitDepth();
 print(ImageType);
 if(ImageType==24){//Is the image RGB?;
 makeFontColorThis=getValue("color.foreground");//Use the color picker to select the color for RGB images
 }else{
         getStatistics(ImageArea,ImageMean,ImageMin,ImageMax);//
         //makeFontColorThis=ImageMin;//sets drawing line to the same value as the minimum; maybe be black or may be white...depends on your LUT and whether image is inverted or not
         makeFontColorThis=ImageMax;//sets drawing line to the same value as the maximum; maybe be black or may be white...depends on your LUT and whether image is inverted or not
 }
 setColor(makeFontColorThis);
 for (j=1; j<nrow; j++)  {
   y = yoff + 15 + (j-1)*130;
   for (i=1; i<ncol; i++) {
     x = xoff + 15 + (i-1)*130;
     if(ImageType==24){//this bit with drawing the oval is strange, but I wasn't able to get the ovals and text colors to match when using the setFont("user") function below...????
         makeOval(x,y,101,101);
         run("Draw");
     }else{
     drawOval(x,y,101,101);
     }
     run("Select None");
   }  // i
 }  // j
 getPixelSize(un, ppx, ppy);
 Len = nrow * ncol * PI * 100 / ppx;
 //setFont("Geneva", 10);//tyoe in the font and size
 setFont("user");//you can set the font under Edit>Options>Fonts
 drawString("Total Length= "+Len+" "+un,2,pht-6);//set the position of the string with the last two inputs
 area=pwd*pht/(ppx*ppx);
 drawString("Total Area= "+area+" "+un,2,pht-18); //set the position of the string with the last two inputs
} // end


 macro "Random Lines"{
//If images are RGB, use the color picker Image>Color>Color picker... to set the color of ovals or lines and text
//If images are grayscale, ovals, lines, and text will be set to either black or white in the appropriate place below
 pwd = getWidth();
 pht = getHeight();
 setLineWidth(1);
len=0;
k=0;
limit=3*(pwd+pht);
 ImageType=bitDepth();
 print(ImageType);
 if(ImageType==24){//Is the image RGB?;
 makeFontColorThis=getValue("color.foreground");//Use the color picker to select the color for RGB images
 }else{
         getStatistics(ImageArea,ImageMean,ImageMin,ImageMax);//
         //makeFontColorThis=ImageMin;//sets drawing line to the same value as the minimum; maybe be black or may be white...depends on your LUT and whether image is inverted or not
         makeFontColorThis=ImageMax;//sets drawing line to the same value as the maximum; maybe be black or may be white...depends on your LUT and whether image is inverted or not
 }
 setColor(makeFontColorThis);
while(len<=limit){
x=round(random*pwd);
y=round(random*pht);
theta=random*3.14159265;
m=sin(theta)/cos(theta);
x1=0;
y1=y+m*(x1-x);
if(y1<0){
y=0;
x1=x+(y1-y)/m;
}
if(y1>pht){
y1=pht;
x1=x+(y1-y)/m;
}
x2=pwd;
y2=y+m*(x2-x);
if(y2<0){
y2=0;
x2=x+(y2-y)/m;
}
if(y2>pht){
y2=pht;
x2=x+(y2-y)/m;
}
     if(ImageType==24){//this bit with drawing the oval is strange, but I wasn't able to get the ovals and text colors to match when using the setFont("user") function below...????
         makeLine(x1,y1,x2,y2);
         run("Draw");
     }else{
     drawLine(x1,y1,x2,y2);
     }
len=len+sqrt((x2-x1)*(x2-x1)+(y1-y2)*(y1-y2));
k=k+1;
}
getPixelSize(un, ppx, ppy);
area=pwd*pht/(ppx*ppx);
 //setFont("Geneva", 10);//tyoe in the font and size
 setFont("user");//you can set the font under Edit>Options>Fonts
 drawString("Total Length= "+len+" "+un,2,pht-6);//set the position of the string with the last two inputs
 area=pwd*pht/(ppx*ppx);
 drawString("Total Area= "+area+" "+un,2,pht-18); //set the position of the string with the last two inputs
}//end




________________________________________
From: Cammer, Michael [[hidden email]]
Sent: Friday, March 15, 2013 11:14 AM
To: List IMAGEJ
Subject: Re: Converting NIH image Macros to the ImageJ ones

I think this works up to the GetScale command where I stopped.  Maybe someone else will have a few minutes to finish this; I have to get back to the laser aligning part of my job.  Also, setting the colors would be a good thing to add.
Regards,
Michael

macro "Circle Grid" {
  pwd = getWidth();
  pht = getHeight();
  setLineWidth(1);
  nrow = pht / 120;
  ncol =pwd / 120;
  xoff = (pwd - 130 * ncol) / 2;
  yoff = (pht - 130 * nrow) / 2;
  for (j=1; j<nrow; j++)  {
    y = yoff + 15 + (j-1)*130;
    for (i=1; i<ncol; i++) {
      x = xoff + 15 + (i-1)*130;
      makeOval(x,y,101,101);
      run("Draw");
      run("Select None");
    }  // i
  }  // j

  GetScale(ppx,un);
  Len = nrow * ncol * pi * 100 / ppx;
  MoveTo (2,pht-6);
  SetFont('Geneva');
  SetFontSize(10);
  Write('Total Length=',Len:10:4,' ',un);
  area:=pwd*pht/(ppx*ppx);
  MoveTo (2,pht-18);
  Write('Total Area=',area:10:3,' sq.',un);

} // end

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Ali Soleimani
Sent: Friday, March 15, 2013 10:40 AM
To: [hidden email]
Subject: Converting NIH image Macros to the ImageJ ones

Dear ImageJ users,

I have found two macros called "Circle Grid" and "Random Lines"   in a
Stereology book ( by J. C. Russ ) which are written in NIH image macro language. I tried to follow the commands and repeat them in ImageJ via macro record but  no success sofar! Is any of you able to convert such a Macro to ImageJ macro or plugin so that it can be used in ImageJ? Thank you.

Best Regards,

Ali


Macro 'Circle Grid';
var
i,j,x,y,xoff,yoff,pwd,pht,nrow,ncol: integer;
len,area,ppx,pi: real;
un: string;
Begin
GetPicSize(pwd,pht);
SetLineWidth(1);
pi:=3.14159265;
nrow:=pht Div 120;
ncol:=pwd Div 120;
xoff:=(pwd - 130*ncol) Div 2;
yoff:=(pht - 130*nrow) Div 2;
For j:=1 To nrow Do
Begin
y:= yoff + 15 + (j-1)*130;
For i:=1 To ncol Do
Begin
x:= xoff + 15 + (i-1)*130;
MakeOvalRoi(x,y,101,101);
DrawBoundary;
KillRoi;
End;
End;
GetScale(ppx,un);
 Len:=nrow*ncol*pi*100/ppx;
MoveTo (2,pht-6);
SetFont('Geneva');
SetFontSize(10);
Write('Total Length=',Len:10:4,' ',un);
area:=pwd*pht/(ppx*ppx);
MoveTo (2,pht-18);
Write('Total Area=',area:10:3,' sq.',un); End;

----------------------------------
Macro 'Random Lines';

Var
i,j,k,x1,x2,y1,y2,pwd,pht,len,limt: integer;
x,y,theta,m,area,ppx,dummy: real;
un: string;
Begin
GetPicSize(pwd,pht);
len:=0;
k:=0;
limt:=3*(pwd+pht); {minimum total length in pixels} Repeat {Until length>limt} x:=Random*pwd; y:=Random*pht; theta:=Random*3.14159265; m:=Sin(theta)/Cos(theta); x1:=0; y1:=y+m*(x1-x); If (y1<0) Then Begin y1:=0; x1:=x+(y1-y)/m; End; If (y1>pht) Then Begin y1:=pht; x1:=x+(y1-y)/m; End; x2:=pwd; y2:=y+m*(x2-x); If (y2<0) Then Begin y2:=0; x2:=x+(y2-y)/m; End; If (y2>pht) Then Begin y2:=pht; x2:=x+(y2-y)/m; End; MoveTo(x1,y1); LineTo(x2,y2);
len:=len+Sqrt((x2-x1)*(x2-x1)+(y1-y2)*(y1-y2))
k:=k+1;
Until (len>limt);
GetScale(ppx,un);
area:=pwd*pht/(ppx*ppx);
SetFont('Geneva');
SetFontSize(10);
MoveTo (2,pht-18);
Write('Total Area=',area:10:3,'sq.',un); len:=len/ppx; MoveTo (2,pht-6); Write('Total Length=',len:10:3,' ',un); End;

--------------------

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

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

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