{ INCLUSION COUNTER: Batch Count Inclusions v1.0 Jeremy Brown 1997 --------------------------------------------------------- You must have run the macro "Help With Paths" when you first installed Inclusion counter on this Mac or these macros WILL NOT RUN! If you did not, DO SO NOW! This macro-file must be loaded into NIH Image to run. To Load "Batch Count Inclusions v1.0" choose "Load Macros From Window" from the "Special" menu then close this window. Alternatively press Apple-9 followed by Apple-W. The range of macros that constitute this part of Inclusion Counter will then be displayed in the "Special" menu. --------------------------------------------------------- } Var left,top,width,height,ImageScale,MaxArea,TotalMaxArea,MinArea,TotalMinArea, MeanValue, n, m, radius, q, i, lower, upper, min, max, x1,x2,y1,y2,ignore1:integer; Sum, SumOfSquares:Boolean; ImageUnits:String; procedure ApplyROI; begin Open('PASTEHERE'); end; end; procedure CheckForStack; begin if nPics=0 then begin PutMessage('This macro requires a stack! Please open your Infected and Uninfected control Images and choose "Windows to Stack" from the Stacks menu.'); exit; end; if nSlices=0 then begin PutMessage('This window is not a stack! Please open your Infected and Uninfected control Images and choose "Windows to Stack" from the Stacks menu.'); exit end; end; procedure CheckStack; begin if nPics=0 then begin PutMessage('This macro requires a RGB stack! Please open a typical example image of infected cells.'); exit; end; if nSlices=0 then begin PutMessage('This window is not a stack! Please cheack the format of the images, see the mannual for details.'); exit; end; end; Procedure MaxMin; begin SetOptions('Area'); {may want to add other options} SetParticleSize(1,10000); {as desired} MinArea:=1; MaxArea:=10000; for i:=1 to rcount do begin if i=1 then begin MinArea:=rArea[i]; MaxArea:=rArea[i]; end else begin if rArea[i]>MaxArea then MaxArea:=rArea[i]; if rArea[i]MaxArea then MaxArea:=rArea[i]; if rArea[i]" keys to move Backward and Forward'); WriteLn(' through the Stack.'); WriteLn(''); WriteLn(''); WriteLn(' The Profile Plot runs from the top left corner to the '); WriteLn(' bottom right corner.'); WriteLn(' You can use the "Plot Profile" tool from the "Tools" Window'); WriteLn(' (Highlighted) for further manual measurements if you wish. '); WriteLn(''); WriteLn(' Draw across a sample inclusion and some cellular '); WriteLn(' background.'); WriteLn(''); SaveAs('Channels Stack'); SelectTool('Profile'); end; end; macro '(---'; begin end; macro '[1] Set Region of Interest'; begin SetSaveAs('Outline'); SaveAs('PASTEHERE');{643} end; end; macro '[2] Calculate Background subtraction'; begin GetLine(x1,y1,x2,y2,ignore1); if x1<0 then begin PutMessage('This macro requires a line selection to determine the rollingball radius. Use the line selection tool to draw it.'); exit; end; ResetCounter; SetScale(0,'pixel'); Measure; Radius := rLength[rCount]; PutMessage('RollingBallRadius = ',Radius); PutMessage('Move the rolling ball across image, if at any point the ball is completely (100%) filled by particle then the radius is too small'); MakeOvalRoi(x1,y1,Radius,Radius); end; end; macro '(---'; begin end; macro 'Grey Scale. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 1000 do begin; open('Image.',q:4); ApplyROI; SubtractBackground('2D Rolling Ball', radius); Smooth; SelectAll; SaveAs('Subtracted.',q:4); Dispose; end; end; macro '24 bit TIFF to Grey Scale. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 1000 do begin; open('Image.',q:4); AverageSlices; ApplyROI; SubtractBackground('2D Rolling Ball',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; Selectwindow('Image.',q:4); Dispose; end; end; macro 'Red Channel. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 10000 do begin; open('Image.',q:4); Red; ApplyROI; SubtractBackground('2D Rolling Ball',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; end; end; macro 'Green Channel. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 10000 do begin; open('Image.',q:4); Green; ApplyROI; SubtractBackground('2D Rolling Ball',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; end; end; macro 'Blue Channel. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 10000 do begin; open('Image.',q:4); Blue; ApplyROI; SubtractBackground('2D Rolling Ball',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; end; end; macro 'Red and Green Channels. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 10000 do begin; open('Image.',q:4); RedGreen; ApplyROI; SubtractBackground('2D Rolling Ball',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; Selectwindow('Image.',q:4); Dispose; end; end; macro 'Red and Blue Channels. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 10000 do begin; open('Image.',q:4); RedBlue; ApplyROI; SubtractBackground('2D Rolling Ball',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; Selectwindow('Image.',q:4); Dispose; end; end; macro 'Green and Blue Channels. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 10000 do begin; open('Image.',q:4); GreenBlue; ApplyROI; SubtractBackground('2D Rolling Ball',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; Selectwindow('Image.',q:4); Dispose; end; end; macro '(---'; begin end; macro 'Fast Grey Scale. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 1000 do begin; open('Image.',q:4); ApplyROI; SubtractBackground('2D Rolling Ball (faster)', radius); Smooth; SelectAll; SaveAs('Subtracted.',q:4); Dispose; end; end; macro 'Fast 24 bit TIFF to Grey Scale. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 1000 do begin; open('Image.',q:4); AverageSlices; ApplyROI; SubtractBackground('2D Rolling Ball (faster)',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; Selectwindow('Image.',q:4); Dispose; end; end; macro 'Fast Red Channel. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 10000 do begin; open('Image.',q:4); Red; ApplyROI; SubtractBackground('2D Rolling Ball (faster)',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; end; end; macro 'Fast Green Channel. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 10000 do begin; open('Image.',q:4); Green; ApplyROI; SubtractBackground('2D Rolling Ball (faster)',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; end; end; macro 'Fast Blue Channel. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 10000 do begin; open('Image.',q:4); Blue; ApplyROI; SubtractBackground('2D Rolling Ball (faster)',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; end; end; macro 'Fast Red and Green Channels. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 10000 do begin; open('Image.',q:4); RedGreen; ApplyROI; SubtractBackground('2D Rolling Ball (faster)',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; Selectwindow('Image.',q:4); Dispose; end; end; macro 'Fast Red and Blue Channels. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 10000 do begin; open('Image.',q:4); RedBlue; ApplyROI; SubtractBackground('2D Rolling Ball (faster)',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; Selectwindow('Image.',q:4); Dispose; end; end; macro 'Fast Green and Blue Channels. Background Subtraction'; { Image names must be in the form 'image.0001', 'image.0002', ..., but this can be changed. } Var q : integer; begin radius:=GetNumber('Rolling ball radius (pixels):',100); for q:= 1 to 10000 do begin; open('Image.',q:4); GreenBlue; ApplyROI; SubtractBackground('2D Rolling Ball (faster)',radius); Smooth; SelectAll; SetSaveAs('Tiff'); SaveAs('Subtracted.',q:4); Dispose; Selectwindow('Image.',q:4); Dispose; end; end; macro '(---'; begin end; Macro '[3] Tell me how to estimate particle size range!' begin PutMessage('First you need to make a stack of some the Background Subtraction images you have just created. Open four UNINFECTED controls and four INFECTED controls.'); PutMessage('Once you have opened the appropriate images choose "Windows to Stack" from the Stacks menu. Then save the stack.'); PutMessage('Play about with the Density Slice Settings under the "Options" menu, then choose "[4] Positive and Negative Controls I. Analyze Particles".'); end; end; Macro '[4] Positive and Negative Controls I. Analyze Particles' begin CheckForStack; NewTextWindow('Controls'); WriteLn('Particles Mean Area Maximum Area Minimum Area'); Lower:= GetNumber('Please Enter the Lower Density Slice Value', 80,0); Upper:= GetNumber('Please Enter the Upper Density Slice Value', 255,0); for i:= 1 to nSlices do begin SetParticleSize(1, 10000); SelectSlice(i); SetScale(0,'pixels'); ApplyROI; SetDensitySlice (Lower, Upper); AnalyzeParticles('Outline,Label,Reset'); If (rCount=0) then begin; SelectWindow ('Controls'); WriteLn (' 0 0 0 0'); End Else Begin; Write(rCount); MeanAreaValue; MaxMin; end; end; PutMessage('Note the "Maximum Area" values returned for the Uninfected Controls. Set the "minimum Inclusion size" above this, these particles represent normal cellular background.'); PutMessage('Then look through the stack and see what kind of particles have been counted. Use the < and > keys to move backwards and forwards through the stack.'); PutMessage('Once you are finished go back to the stack you saved after Positive and negative Controls I. Then run Positive and negative Controls II. Inclusions size.'); end; end; Macro '[5] Positive and Negative Controls II . Inclusion Size' begin CheckForStack; NewTextWindow('Controls II'); WriteLn('Inclusions Mean Area Maximum Area Minimum Area STDEV'); Lower:= GetNumber('Please Enter the Lower Density Slice Value', 100,0); Upper:= GetNumber('Please Enter the Upper Density Slice Value', 255,0); min:= GetNumber('Please Enter minimum Inclusion size', 25); max:= GetNumber('Please Enter maximum Inclusion size', 10000); for i:= 1 to nSlices do begin SetParticleSize(min, max); SelectSlice(i); SetScale(0,'pixels'); ApplyROI; SetDensitySlice (Lower, Upper); AnalyzeParticles('Outline,Label,Reset'); If (rCount=0) then begin; SelectWindow ('Controls II'); WriteLn (' 0 0 0 0 0'); End Else Begin; SelectWindow ('Controls II'); Write(rCount); MeanAreaValue; MaxMin2; Write(' '); StandardDeviation2; end; end; PutMessage('Check through the stack to make sure all the inclusions have been counted. You may need to go back and fine tune the density slice and particle size settings at this point.'); PutMessage('Once you are happy with the results, and have recorded all the variables you need, you can go on to "Background Subtracted Images. Automated Inclusion Enumeration".'); end; end; Macro '[6] Set Scale part 1' begin PutMessage('Open an image of a graticule or other object of known dimensions at the same magnification as the images you wish process in this session.'); Open(''); PutMessage('This macro requires a line selection to set the scale. Use the line selection tool to trace a known distance on the graticule. Then run macro "Set Scale part 2".'); end; end; Macro '[7] Set Scale part 2' begin PutMessage('Before you proceed make sure that you have run the macro "Set Scale part 2" or completed the steps outlined therein. Fill in the KNOWN DISTANCE and Record the SCALE. '); SetScale(0, '' ); end; end; macro '(---'; begin end; Macro '[8] Background Subtracted Images. Automated Inclusion Enumeration'; { Image names must be in the form 'Subtracted.0001', 'Subtracted.0002', ..., but this can be changed. } begin ImageScale:=GetNumber('What is the scale of the images:', 1.125); ImageUnits:=GetString('What are the units of measurement:', ' µm2'); Lower:= GetNumber('Please Enter the Lower Density Slice Value', 100,0); Upper:= GetNumber('Please Enter the Upper Density Slice Value', 255,0); min:= GetNumber('Please Enter minimum Inclusion size', 50); max:= GetNumber('Please Enter maximum Inclusion size', 10000); NewTextWindow('Inclusions'); SaveAs('Inclusions'); Write('Inclusions Area', ImageUnits ' STDEV'); ROISize; for q:= 1 to 10000 do begin; open('Subtracted.',q:4); SetScale(ImageScale, ' ImageUnits'); SetParticleSize(min, max); ApplyROI; SetDensitySlice (lower, upper); MakeBinary; ApplyROI; DeleteTouching; ApplyROI; erode; dilate; AnalyzeParticles('Outline,Label,Reset'); If (rCount=0) then begin; SelectWindow ('Inclusions'); WriteLn (' 0 0 0'); End Else Begin; SelectWindow ('Inclusions'); Write(rCount); MeanAreaValue; StandardDeviation; Save; end; SelectWindow ('Subtracted.',q:4); SelectAll; SaveAs ('Binary.' ,q:4); Dispose; end; end;