{Varve300.itm - script file program for Image Tool 3.0 to measure varve thicknesses (summer, winter, total). This version of the program will allow up to 4 double digit comments to be entered for each couplet as an integer code.} macro 'process|Varve|Couplet Measurement [1]'; { variable declarations go here } var ph,pt,begin_n,get_type1,sav_pos,bedn_tt,bedn,pidn,bitsize,n,k,x,y,width,height,anno1:integer; imnuma,b,imnum,i,j,org_beg,last_num:integer; Scale,aspectratio,total,running,top,last_running:real; cnt_text,get_type2,Unit,core,title,window,runstring:string; p1,backup1,backup2,backup3,backup4,backup5,backup6,bed_pos,x_pos,Annim,Ann1,Acount,Asummer,Awinter,Atotal,Arunning:array; save_key,anno_key,exit_key,err_key, Calibration:boolean; begin ShowMessage('VARVE ANALYSIS MACROS: written by Nathaniel J. Toll and Shuai Yuan at Tufts University'); SetText('top'); { opening user specified image set} Core:=GetString('Set Open?'); get_type1:=GetNumber('Image file format?(enter 1 for BMP, 2 for JPG, 3 for other types)',1); if (get_type1=3) then begin get_type2:=GetString('Please input image file extension:(3 letter or number)'); end; imnuma:=GetNumber('Starting image?',1); last_num:=0; running:=0; if (imnuma>1) then begin last_num:=GetNumber('What is the couplet number of last saved varve',1); runstring:=GetString('What is the starting value for the running total?',0); running:=StringToNum(runstring); end; imnum:=GetNumber('Ending image?',imnuma); org_beg:=0+last_num; ShowResults(FALSE); {loop for opening images} for n:=imnuma to imnum do begin title:='c:\\images\\RAWVRV\\'; b:=imnum- (n-imnuma); if (get_type1=1) then begin Open('c:\\images\\RAWVRV\\',core,'-',b:1,'.bmp'); saveas('c:\\images\\processed\\',core,'-',b:1,'.bmp'); RotateRight(false); p1[n]:= PidNumber; SaveAs('c:\\images\\processed\\',core,'-',b:1,'_vertical','.bmp'); end else if (get_type1=2) then begin Open('c:\\images\\RAWVRV\\',core,'-',b:1,'.jpg'); saveas('c:\\images\\processed\\',core,'-',b:1,'.bmp'); RotateRight(false); p1[n]:= PidNumber; SaveAs('c:\\images\\processed\\',core,'-',b:1,'_vertical','.bmp'); end else begin Open('c:\\images\\RAWVRV\\',core,'-',b:1,'.',get_type2); saveas('c:\\images\\processed\\',core,'-',b:1,'.bmp'); RotateRight(false); p1[n]:= PidNumber; SaveAs('c:\\images\\processed\\',core,'-',b:1,'_vertical','.bmp'); end; if (get_type1=1) then begin window:=concat(core,'-',b:1,'.bmp'); end else if (get_type1=2) then begin window:=concat(core,'-',b:1,'.jpg'); end else begin window:=concat(core,'-',b:1,'.',get_type2); end; SelectWindow(window); Close; end; CascadeWindows; ShowResults(FALSE); bedn_tt:=0; SetNewSize(270,90); MakeNewWindow('Hints'); MoveWindow(500,100); begin_n:=0; for n:=imnuma to imnum do begin bedn:=1; {promt for user to arrange window initially} ShowMessage('Please arrange Images for analysis. Click on the image to be measured when they are arranged, press shift when done'); SelectWindow('Hints'); MakeRoi(0,0,269,89); SetForeGroundColor(155,155,155); MakeAnnotation(0,'fill'); SetForeGroundColor(0,0,0); SetFontSize(11); SetText('top'); MoveTo(10,5); Write('Click on the image to be processed, '); MoveTo(10,35); Write('and press SHIFT for calibration'); ph:=PidNumber; repeat wait(0); pt:=PidNumber; Until (KeyDown('shift') AND ((pt>ph) OR (pt10) AND (y>0)); if (exit_key=false)AND(err_key=false) then begin GetRow(1, y, width); if (odd(bedn)) then begin for j:= 1 to width do begin if (sav_pos=1) then backup1[j]:=redpixel[j]; if (sav_pos=2) then backup2[j]:=redpixel[j]; if (sav_pos=3) then backup3[j]:=redpixel[j]; if (sav_pos=4) then backup4[j]:=redpixel[j]; if (sav_pos=5) then backup5[j]:=redpixel[j]; if (sav_pos=6) then backup6[j]:=redpixel[j]; if (sav_pos>6) then sav_pos:=sav_pos-6; end; for k:=x to width-25 do begin redpixel[k] := 255; end; sav_pos:=sav_pos+1; PutRow(1,y,width); bed_pos[bedn]:=y; x_pos[bedn]:=x; if (bedn>1) AND (bed_pos[bedn]>bed_pos[bedn-1]) then showmessage('A negative value bed will be recorded unless revised'); end; if (NOT(odd(bedn))) then begin for j:= 1 to width do begin if (sav_pos=1) then backup1[j]:=bluepixel[j]; if (sav_pos=2) then backup2[j]:=bluepixel[j]; if (sav_pos=3) then backup3[j]:=bluepixel[j]; if (sav_pos=4) then backup4[j]:=bluepixel[j]; if (sav_pos=5) then backup5[j]:=bluepixel[j]; if (sav_pos=6) then backup6[j]:=bluepixel[j]; if (sav_pos>6) then sav_pos:=sav_pos-6; end; for k:=x to width-25 do begin bluepixel[k] := 255; end; sav_pos:=sav_pos+1; PutRow(1,y,width); bed_pos[bedn]:=y; x_pos[bedn]:=x; if (bedn>1) AND (bed_pos[bedn]>bed_pos[bedn-1]) then showmessage('A negative value bed will be recorded unless revised'); if (bedn=2) then Annim[1+begin_n]:=n; if (bedn=2) then Ann1[1+begin_n]:=0; end; bedn:=bedn+1; end; if (err_key) then begin bedn:=bedn-1; if (bedn>0) then begin y:=bed_pos[bedn]; GetRow(1, y, width); sav_pos:=sav_pos-1; if (odd(bedn)) then begin for j:= 1 to width do begin if (sav_pos<1) then sav_pos:=sav_pos+6; if (sav_pos=1) then redpixel[j]:=backup1[j]; if (sav_pos=2) then redpixel[j]:=backup2[j]; if (sav_pos=3) then redpixel[j]:=backup3[j]; if (sav_pos=4) then redpixel[j]:=backup4[j]; if (sav_pos=5) then redpixel[j]:=backup5[j]; if (sav_pos=6) then redpixel[j]:=backup6[j]; end; PutRow(1, y, width); end; if (NOT(odd(bedn))) then begin for j:= 1 to width do begin if (sav_pos<1) then sav_pos:=sav_pos+6; if (sav_pos=1) then bluepixel[j]:=backup1[j]; if (sav_pos=2) then bluepixel[j]:=backup2[j]; if (sav_pos=3) then bluepixel[j]:=backup3[j]; if (sav_pos=4) then bluepixel[j]:=backup4[j]; if (sav_pos=5) then bluepixel[j]:=backup5[j]; if (sav_pos=6) then bluepixel[j]:=backup6[j]; end; PutRow(1, y, width); end; end; if (bedn=0) then bedn:=1; end; if (exit_key=false) then exit_key:=Keydown('control'); until (exit_key)AND(NOT(odd(bedn))); save_key:=ShowMessageCancel('Click OK to save the results or click cancel to restart?'); if (save_key=true) then begin close; open('c:\\images\\processed\\',core,'-',n:1,'_vertical','.bmp'); bedn:=1; end; until(save_key=false); If n=imnum then begin ShowMessage('Please indicate the top of the core by clicking on it'); repeat wait(0); until Button; repeat wait(.2); until Button; GetMouse(x,y); top:=y; SetForegroundColor(255,255,0); MoveTo(0,top); LineTo(width,top); top:=((bed_pos[1]-top)/scale)+running; end; for j:=1 to (bedn-2)/2 do begin Asummer[j+begin_n]:=-(bed_pos[2*j]-bed_pos[2*j-1])/scale; Awinter[j+begin_n]:=-(bed_pos[2*j+1]-bed_pos[2*j])/scale; Atotal[j+begin_n]:=Asummer[j+begin_n]+Awinter[j+begin_n]; running:=running+Atotal[j+begin_n]; Arunning[j+begin_n]:=running; end; GetPicSize(width,height); for j:=1 to bedn-1 do begin if (odd(j)) then begin SetForeGroundColor(255,0,0); MoveTo(x_pos[j],bed_pos[j]); LineTo(width-2,bed_pos[j]); end; if (NOT(odd(j))) then begin SetForeGroundColor(0,0,255); MoveTo(x_pos[j],bed_pos[j]); LineTo(width-20,bed_pos[j]); end; end; for j:=1 to (bedn-2)/2 do begin SetForegroundcolor(255,120,0); MoveTo(width-70,bed_pos[2*j]-10); Write(j+begin_n+org_beg); end; if (bedn>4) then begin for j:=2+begin_n to begin_n+(bedn-2)/2 do begin Annim[j]:=0; Ann1[j]:=0; end; end; begin_n:=begin_n+(bedn-2)/2; moveto(width-160,height-20); SetForegroundcolor(0,255,0); SetText('bold'); SetFont('arial'); SetFontSize(14); write(core,'-',n:1); SetText('bold'); SetFont('times'); SetFontSize(12); SetForegroundcolor(0,130,255); moveto(width-200,height-5); write('Tufts University'); MergeAnnotationsIntoImage; Saveas('c:\\images\\ANALVRV\\',core,'-',n:1,'_cnt','.bmp'); { Annotation} repeat anno_key:=ShowMessageCancel('Click OK to add an annotation in this image'); if (anno_key=false) then begin k:=GetNumber('What is the couplet number to be annotated?',org_beg+1); if (k>org_beg)AND(k<=org_beg+begin_n) then begin anno1:=GetNumber('What is the annotation (Integer, must be 8 digits, fill with zeroes to complete)',0); Ann1[k-org_beg]:=anno1; end; end; until(anno_key=true); cnt_text:=concat(core,'-',n:1,'_cnt'); MakeNewTextWindow(cnt_text); SelectWindow(cnt_text); writeln('Data for core: ',core,' images ',n); Writeln('COUNT ',' ','SUMMER ',' ','WINTER ',' ','COUPLET',' ','TOTAL',' ','IM',' ','COMMENT#s'); { for j:=begin_n-(bedn-2)/2+1 to begin_n do begin } for j:=1 to begin_n do begin Writeln((j+org_beg):4,' ',Asummer[j]:7:3,' ',Awinter[j]:7:3,' ',Atotal[j]:7:3,' ',Arunning[j]:7:3,' ',Annim[j],' ',Ann1[j]); end; saveas('c:\\images\\Result\\',core,'-',n:1,'_cnt','.txt'); close; end; ShowResults(false); if (get_type1=1) then begin for n:= imnuma to imnum do begin window:=concat(core,'-',n:1,'_vertical','.bmp'); selectWindow(window); close; end; end; MakeNewTextWindow(core); SelectWindow(core); writeln('Data for core: ',core,' images',imnuma,'-',imnum); Writeln('COUNT ',' ','SUMMER ',' ','WINTER ',' ','COUPLET',' ','TOTAL',' ','IM',' ','COMMENT#s'); for n:=1 to begin_n do begin Writeln((n+org_beg):4,' ',Asummer[n]:7:3,' ',Awinter[n]:7:3,' ',Atotal[n]:7:3,' ',Arunning[n]:7:3,' ',Annim[n],' ',Ann1[n]); end; Writeln(''); Writeln('Distance from beginning of image range measurement to top of core =: ',top:7:3); SelectWindow(core); if (imnuma=1) then saveas('c:\\images\\Result\\',core,'_varve','.txt'); if (imnuma>1) then saveas('c:\\images\\Result\\',core,'_varve_from_',imnuma,'.txt'); discardresults; SelectWindow('Hints'); MakeRoi(0,0,269,89); SetForeGroundColor(155,155,155); MakeAnnotation(0,'fill'); SetFontSize(11); SetForeGroundColor(0,0,0); setText('top'); MoveTo(10,5); Write('Program finished.'); MoveTo(10,35); Write('Results are saved in'); MoveTo(10,65); if (imnuma=1) then Write('c:\\images\\result\\',core,'_varve','.txt'); if (imnuma>1) then Write('c:\\images\\result\\',core,'_varve_from_',imnuma,'.txt'); end;