{Date: Tue, 10 Aug 93 15:52:11 PDT From: karl%pluto.dnet@loni.ucla.edu To: "hammer@wana.pbrc.Hawaii.Edu"%GATE.dnet@loni.ucla.edu Subject: Re: Posting on Image list To: Anyone interested in my grain counting macros I am pleased that some people are interested in the grain counting macros that I wrote. As I don't do grain counting myself, they have not been tested in 'real world' image analysis, and I have had limited feedback to help me refine them. I welcome feedback for debugging and finding missing essential features, BUT I will be on vacation until Aug. 28 and so cannot respond immediately.The macros are relatively simple and straightforward, so feel free to edit them. There are four macros that ASSIST in grain counting, but it is far from automatic. You must set the Max Measurements to 1000 in the Analyze Options dialog box, and can make a maximum of 999 measurements. Use Set Scale to get areas and densities in real units. GRAINS MUST BE DISTINGUISHABLE BY GRAY SCALE ALONE! Image enhancement and editing is to be done beforehand. Fix LUT - changes black(255) and white(0) pixels to very dark gray(254) and very light gray(1), so that all pixels are within the LUT. Calibrate Area per Grain - initializes a few things, and expects that you have selected several 'typical' grains for an average calibration with a selection tool. It asks for the number of grains selected, calculates and stores the calibration. Count Grains in Area - expects that you have selected your area of interest with a selection tool, and previously calibrated the grains. Grays out and numbers your area, and records area, number of grains, and density (grains/unit area) in the results table. Verify Calibration - Works like 'Calibrate Area per Grain' but does not change anything. Simply reports previous calibration and verification. If the discepency is too large you must re-'Calibrate Area per Grain'. THIS RESETS THE RESULTS TABLE SO >>>!!SAVE IT FIRST!!<<< Have fun, and I hope their useful. Reply to: (after Aug. 28) karl@loni.ucla.edu regardless where this message appears to come from. --------MACRO FILE FOLLOWS----------------------------------------------} {Grain Counting Macros } {written by Karl Beykirch 1993} macro 'Fix LUT [F5]'; begin ChangeValues(255,255,254); ChangeValues(0,0,1); end; macro 'Calibrate Area per Grain [F6]' var pix,part,i,foo,width:integer; begin RequiresVersion(1.49); GetRoi(foo,foo,width,foo); if width=0 then begin PutMessage('You have not selected an area!!'); exit; end; SetOptions('Area, User1, User2'); SetUser1Label('Grains'); SetUser2Label('Density'); SetPrecision(4); SetForegroundColor(255); SetBackgroundColor(0); Copy; KillRoi; MakeNewWindow('Temp'); Paste; SetDensitySlice(255,255); Measure; GetResults(pix,foo,foo,foo,foo); part:=GetNumber('Enter Number of Grains Selected:',1); Dispose; ResetCounter; rUser2[1000]:=pix/part; SetNewSize(275,50); MakeNewWindow('Grain Size Calibrated'); MoveTo(10,25); Write('Grain size calibrated as ',rUser2[1000]:5:2,' pixels / grain .'); SetNewSize(640,480); end; macro 'Count Grains in Area [F7]' var pixpart:real; area,pix,i,foo,left,top,width,height:integer; begin if rUser2[1000]=0 then begin PutMessage('Grain size is NOT calibrated!!'); exit; end; GetRoi(left,top,width,height); if width=0 then begin PutMessage('You have not selected an area!!'); exit; end; SetBackgroundColor(0); Copy; i:=rCount; SetForegroundColor(128); Fill; SetForegroundColor(255); MoveTo(left+(width/2),top+(height/2)); Write(i+1); KillRoi; MakeNewWindow('Temp'); Paste; SetDensitySlice(255,255); Measure; Dispose; rUser1[i+1]:=rArea[i+1]/rUser2[1000]; SetCounter(i); MakeNewWindow('Temp'); Paste; SetThreshold(1); Measure; GetResults(pix,foo,foo,foo,foo); Dispose; rUser2[i+1]:=rUser1[i+1]/pix; end; macro 'Verify Calibration [F8]' var verif:real pix,part,i,foo,width:integer; begin GetRoi(foo,foo,width,foo); if width=0 then begin PutMessage('You have not selected an area!!'); exit; end; if rUser2[1000]=0 then begin PutMessage('Grain size is NOT calibrated!!'); exit; end; SetForegroundColor(255); SetBackgroundColor(0); Copy; KillRoi; MakeNewWindow('Temp'); Paste; SetDensitySlice(255,255); i:=rCount; Measure; GetResults(pix,foo,foo,foo,foo); SetCounter(i); part:=GetNumber('Enter Number of Grains Selected:',1); Dispose; verif:=pix/part; SetNewSize(275,50); MakeNewWindow('Grain Size Verification'); MoveTo(10,15); Writeln('Grain size calibrated as ',rUser2[1000]:5:2,' pixels / grain.'); Writeln('Verification calibrated as ',verif:5:2,' pixels / grain .'); SetNewSize(640,480); end;