Macro 'For loop example'; Var i:integer; begin for i := 1 to 10 do begin ShowMessage('This iteration is: ', i); wait(0.5); {just a delay to see the answer in the Info window} {some process} end; {for loop} end; {macro}
Macro 'While loop example'; Var i,MyNumber:integer; begin i:=1; {start the loop at 1} MyNumber:=GetNumber('Enter end of the loop:',10,0); while i<=MyNumber do begin {some process} ShowMessage('This iteration is: ', i); wait(0.5); {just a delay to see the answer in the Info window} i:=i+1; end; {while loop} end; {macro}
Macro 'Loop with step'; Var i,MyNumber, step:integer; begin i:=0; {start the loop at 0} MyNumber:=GetNumber('Enter ending value:',100,0); Step:=GetNumber('Enter step:',10,0); while i<=MyNumber do begin {some process} ShowMessage('i value: ', i); wait(0.5); {just a delay to see the answer in the Info window} i:=i+step; end; end;
Macro 'Repeat loop'; Var i:integer; begin i := 0; Repeat {some process} ShowMessage('This iteration is: ', i); wait(0.5); {just a delay to see the answer in the Info window} i := i +1; until Button; end;
This macro will list your ROI's coordinates.
Macro 'Coordinates'; Var left, top,width,height:integer; begin GetRoi(left,top,width,height); If width = 0 then begin putmessage('no ROI exists'); exit; end; ShowMessage('ROI is ',left,' x units from the left','\', width, ' x units in width','\', top, ' y units below the top edge','\', height, ' y units in height'); end;
GetRoi(left,top,width,height)You will want to call this macro routine if you need any information about the current ROI. The routine returns a width of zero if no ROI exists.
SelectAllThe Selectall macro command is equivalent to the Pascal SelectAll(true), which selects all of the image and shows the ROI's 'marching ants'.
MakeRoi(left,top,width,height)This is as straight forward as the name implies.
MakeOvalRoi(left,top,width,height)Not terribly differing to implement from MakeROI. If you want a circular ROI set width and height to the same value. See the example below.
MoveRoi(dx,dy)Use to move right dx and down dy.
InsetRoi(delta)Expands the ROI if delta is negative, Shrinks the ROI if delta is positive.
macro 'Animate Stack'; var i,delay:integer; begin RequiresVersion(1.56); i:=0; delay:=0.1; repeat i:=i+1; if i>nSlices then i:=1; Wait(delay); SelectSlice(i); if KeyDown('shift') then delay:=1.5*delay; if delay>1 then delay:=1; if KeyDown('control') then delay:=0.66*delay; if KeyDown('option') then beep; ShowMessage('delay=',delay:4:2); until button; end;
rUser1[1]:=SomeNumber; rUser2[1]:=SomeOtherNumber;And similarly retrieve as:
SomeNumber := rUser1[1]; SomeOtherNumber := rUser2[1];
for i:=0 to 255 do begin rArea[i+1]:=RedLut[i]; rMean[i+1]:=GreenLut[i]; rLength[i+1]:=BlueLut[i]; end;Here rArea, rMean and rLength are used for Red, Green and Blue instead of area, mean and length.
Macro 'rCount explaned'; Var i:integer; begin ResetCounter; SetOptions('Mean'); MakeRoi(0,0,5,5); for i := 1 to 10 do begin Measure; MoveRoi(5,0); end; ShowResults; ShowMessage('The final index in the results window is the value of rCount','\\', 'rCount value is: ', rCount); end;
Macro 'SetCounter example'; Var left,top,width,height:integer; begin ResetCounter; SetOptions('rUser1'); SetPrecision(3); SelectAll; GetROI(left,top,width, height); rUser1[1] := width; rUser1[2] := height; rUser1[3] := height/width; SetCounter(3); ShowResults; end;
macro 'Count Black and White Pixels [B]'; { Counts the number of black and white pixels in the current selection and stores the counts in the User1 and User2 columns. } begin RequiresVersion(1.44); SetUser1Label('Black'); SetUser2Label('White'); Measure; rUser1[rCount]:=histogram[255]; rUser2[rCount]:=histogram[0]; UpdateResults; end;
SetExport('Measurements'); Export('YourFileName');
macro 'Reduce Noise'; var i:integer; begin if nSlices=0 then begin PutMessage('This window is not a stack'); exit; end; for i:= 1 to nSlices do begin SelectSlice(i); ReduceNoise; {Call any routine you want, including UserCode} end; end;See the series of stack macros distributed with the Image program for more examples.