ij-macro-programming-workshop

Previous            Exercise            Next

Exercise 15.1 - Measure objects on all images in a folder

Aim:

Complete the macro below and run it on the images in the folder 15.

Useful commands:

Your code starts after this line

run("Set Measurements...", "area mean standard modal min centroid center perimeter bounding fit shape feret's integrated median skewness kurtosis area_fraction display add redirect=None decimal=3");
path = getDirectory("Input directory");			// Ask the user for the input directory
print("\\Clear");
print("batch measure nuclei started");
setBatchMode(true);
files = getFileList(path);						// get an array containing the names of all files in the directory path
File.mkdir(path + "out");						// create the output directory
for(i=0; i<files.length; i++) {					// iterate over all files
	image = files[i];							// get the name of the current file
	print("\\Update1: processing file " + (i+1) +"/" + files.length);
	if (indexOf(image, ".tif") != -1) {			// if the current file is a an image...
		open(path + image);
		setAutoThreshold("Default dark");
		run("Analyze Particles...", "size=400-Infinity show=[Overlay Outlines] display exclude in_situ");
		save(path + "out/" + image);
		close();
	}
}
saveAs("Results", path + "out/" + "Results.xls");
> batch measure nuclei started
>  processing file 3/3
LabelAreaMeanStdDevModeMinMaxXYXMYMPerim.BXBYWidthHeightMajorMinorAngleCirc.FeretIntDenMedianSkewKurt%AreaRawIntDenFeretXFeretYFeretAngleMinFeretARRoundSolidity
A4 dapi 1.tif6101126.28125.55811672222198.15786.649199.33486.776353.0611305013079140.20955.403157.4660.615137.786770438.0001250.293-0.056100770438.00013060158.27656.1492.5310.3950.957
A4 dapi 1.tif7047149.47431.40115772239428.766113.529428.097113.457329.1203717211185115.78177.495158.4200.818115.9531053342.000151-0.192-0.3731001053342.00037392156.08878.6731.4940.6690.973
A4 dapi 1.tif5455126.02426.88713572235199.684160.958200.437161.086292.39214912410371103.92066.835163.8690.802104.393687460.0001260.3160.017100687460.000149153170.62868.8391.5550.6430.964
A4 dapi 1.tif7524145.87032.91915072246353.094213.299353.440212.639328.19130516193104104.25291.891108.3470.878105.5371097527.0001460.097-0.5031001097527.000345161102.58893.0001.1350.8810.980
A4 dapi 1.tif5653135.36023.9311457219864.660237.52665.251237.117300.9781120311169111.80964.374168.1390.784112.792765189.000138-0.410-0.139100765189.00012222165.10164.8281.7370.5760.971
A4 dapi 1.tif6178132.12725.06413272211552.543305.316551.895304.745304.39251325378105105.94874.245102.1520.838107.280816280.000133-0.047-0.373100816280.000540253101.83474.4581.4270.7010.974
A4 dapi 1.tif4583137.21131.46213072224267.902300.119267.431299.934296.39221327210759108.17253.944174.8630.656109.385628839.0001370.024-0.706100628839.000214283165.71058.6212.0050.4990.903
A4 dapi 1.tif7312167.04036.38716772255360.969365.884360.809365.959333.12030132511582115.71580.455175.9460.828115.6241221399.000169-0.336-0.1641001221399.000301362174.04380.7061.4380.6950.978
A4 dapi 1.tif6820123.35025.95712672210497.701459.070499.656459.478343.34545140398109119.93072.404128.0030.727121.083841245.0001230.056-0.814100841245.000462409131.98772.5291.6560.6040.957
nuclei.tif465660.54512.3635441108563.192106.911562.066106.638298.4345137810059100.90258.752179.5350.657100.499281898.000590.9010.918100281898.0005131085.71159.0001.7170.5820.955
nuclei.tif497050.5327.2064141811203.534134.4711203.957134.112440.78411529610776109.55257.763156.4400.321115.836251142.000490.9690.934100251142.0001153109152.77164.3741.8970.5270.861
nuclei.tif753274.95814.249804112593.937139.04293.866138.133342.090349811981118.24781.1013.2620.809119.340564586.00075-0.044-0.006100564586.000341364.32581.0001.4580.6860.976
nuclei.tif477561.40511.439624199783.236152.087783.864152.005285.56373312110263100.56560.4566.4080.736102.313293207.000610.453-0.278100293207.0007331554.48560.9571.6630.6010.962
nuclei.tif483351.5268.226434192337.884180.997338.395181.737366.3163001317410091.09467.55292.4180.453100.404249025.000500.8920.632100249025.00033613195.14374.0001.3490.7420.845
nuclei.tif6251100.67326.71910041197608.970222.146608.832223.448309.6055601779889110.48972.034143.7920.819111.212629307.0001010.2480.567100629307.000566188142.30671.8001.5340.6520.977
nuclei.tif501153.4297.9815141841025.585209.9961025.890209.275411.73096817911862113.06656.4294.4740.371118.106267735.000530.506-0.253100267735.0009682132.42662.0002.0040.4990.883
nuclei.tif384972.97920.0227241157151.210266.861151.426268.349235.522116231707172.46167.63253.7650.87274.404280898.000700.8630.702100280898.00011928636.25468.3331.0710.9330.970
nuclei.tif645487.15419.9688041145822.875297.016823.828297.424313.70676825910979109.87274.792168.1580.824110.476562492.000870.051-0.357100562492.000768289170.62375.6711.4690.6810.976
nuclei.tif3188178.80164.79325541255271.804296.490271.796295.760218.108233269765773.42655.282172.6960.84276.655570016.000201-0.727-0.727100570016.000233290172.50457.0001.3280.7530.970
nuclei.tif623497.97124.77110841177447.669369.441448.157371.505308.97841231472113112.25470.70993.2230.821113.635610752.000100-0.113-0.287100610752.00043931496.06271.6751.5880.6300.977
nuclei.tif434569.55616.0287641123632.013349.023633.947349.268268.534588316916491.81660.253163.9910.75794.921302221.000690.389-0.380100302221.000590331159.65663.7911.5240.6560.964
nuclei.tif669390.93418.04191411611115.890362.5111115.702362.864314.291106331810488109.86377.567150.4040.851111.893608620.000910.0040.799100608620.0001064343155.72678.7331.4160.7060.977
nuclei.tif385966.79613.888684110871.580364.61173.106365.096283.94830329787076.94563.856142.9330.60181.025257765.000670.058-0.561100257765.00037343144.54567.5661.2050.8300.923
nuclei.tif495261.09410.9696241112825.917442.540826.619441.891288.877791394689492.49468.16782.8750.74694.895302539.000600.6740.716100302539.00081748882.12668.0001.3570.7370.963
nuclei.tif358082.80223.57364411431080.880425.3511080.841426.152252.9361037399895491.56749.780168.4720.70390.521296430.000810.247-0.803100296430.0001037411163.96849.1351.8390.5440.960
nuclei.tif422170.78218.2455141132608.141453.411609.522453.896278.877561423926191.91458.471179.5620.68292.779298770.000700.267-0.804100298770.000561450172.56959.5661.5720.6360.956
nuclei.tif450364.72514.7206041116224.243484.957223.192484.824272.877186444778288.65264.673128.8190.76090.802291456.000630.556-0.292100291456.000200448126.49165.7321.3710.7300.963
nuclei.tif398872.20722.1975141138956.706510.815957.509507.859261.907924468669090.19256.29972.6310.73192.655287961.000660.702-0.548100287961.00095155871.76159.7461.6020.6240.937
nuclei.tif316092.74728.13210841171521.876517.710524.533518.359251.664484487726478.27151.404144.0760.62782.662293080.00095-0.008-0.880100293080.000487491145.34954.1131.5230.6570.919
nuclei.tif360882.56325.4205741167654.826546.803656.221547.158237.664615515806279.56157.740163.2850.80382.710297887.000800.427-0.597100297887.000615542165.29259.0321.3780.7260.961
nuclei.tif289996.26525.51711241163806.357564.048807.052563.937205.279778529576968.98753.505111.0550.86570.576279072.00099-0.289-0.568100279072.000795530110.74654.9511.2890.7760.967
nuclei.tif323182.46823.01592411381112.278564.2071111.254564.081231.9071075529736781.66450.37538.1650.75583.217266455.000820.176-0.738100266455.000107658632.73550.7581.6210.6170.954
nuclei.tif390274.75317.6247441145575.921621.152575.602620.027264.049535582828096.68751.384139.6530.70399.358291686.000730.387-0.167100291686.000547584130.10154.9221.8820.5310.944
nuclei.tif413269.42914.2817241121473.660639.632474.657639.937248.936431608816581.86864.262162.8370.83883.726286881.000690.317-0.143100286881.000436622150.68064.9941.2740.7850.971
nuclei.tif462256.69811.250514197703.887654.118703.850654.137355.93165061710670105.04756.022163.0660.458110.164262058.000540.8960.398100262058.000650641164.19759.4791.8750.5330.879
nuclei.tif613287.95020.2058941151206.769671.964207.496672.254314.09015563010385111.69169.903146.0880.781112.379539311.00089-0.119-0.118100539311.000158644150.69871.6841.5980.6260.968
nuclei.tif414461.58410.329604193868.132768.739868.806768.903267.463825731907196.26054.813151.6590.72895.000255205.000610.175-0.435100255205.000835737143.13056.1401.7560.5690.955
nuclei.tif428754.6938.6185441911175.657774.7021176.274775.718270.5341132741856983.46665.397161.4620.73686.608234471.000541.1231.849100234471.0001139751148.69667.5291.2760.7840.938
nuclei.tif448555.62810.5634841106473.298788.017473.738788.238318.8604357437593101.38156.327122.5050.554103.465249492.000540.9930.763100249492.000443747122.76858.0591.8000.5560.934
nuclei.tif400570.45914.8197041114648.668795.914649.423797.291260.735610756777789.13557.209139.3860.74092.849282188.000700.109-0.673100282188.000617759131.07058.7621.5580.6420.948
nuclei.tif546473.88514.853654112779.575806.02480.857805.305279.07839761799189.46477.76391.8510.88291.351403708.000730.3930.205100403708.0007785284.97678.4331.1500.8690.974
nuclei.tif3484144.31949.60818041240317.780811.305318.089811.476227.622286772627472.26861.38280.4310.84574.793502807.000152-0.421-0.795100502807.00029383960.35062.0001.1770.8490.966
nuclei.tif520560.03510.537644198209.712840.461208.941840.475368.316174791709898.19967.488103.6160.48299.464312480.000600.291-0.314100312480.000201792102.77969.5411.4550.6870.946
nuclei.tif511066.32115.9545441124414.876880.721415.240880.828310.676379831739796.27767.579107.2200.66599.690338902.000630.498-0.594100338902.000403831103.33967.7971.4250.7020.952
nuclei.tif417455.2147.921564179870.033900.969870.499901.293271.848832860738590.17358.937124.4130.71090.918230463.000550.320-0.521100230463.000849863119.66760.2011.5300.6540.952
nuclei.tif500180.99919.04186411371094.049925.1691095.130926.610281.8481053882848697.16865.531135.2640.79197.801405078.000810.185-0.148100405078.0001065885127.10465.0541.4830.6740.972
nuclei.tif386557.3459.737574191159.798955.438160.242955.378252.877122919757175.34965.310148.9610.76078.772221640.000560.6510.102100221640.000123939159.95567.8821.1540.8670.947
nuclei.tif386354.92510.5784841102942.878972.056942.554970.288335.44690792373103113.63543.28462.0890.431113.877212176.000531.1111.177100212176.000917102459.38146.4482.6250.3810.863
nuclei.tif395783.24225.9776241161516.635977.698517.225978.815247.421481940717476.77665.62347.5680.81279.025329389.000790.339-0.833100329389.000488100538.32066.9231.1700.8550.961
two-nuclei.tif5880128.12624.15311683222323.42192.891324.51992.926356.2332565712878138.93953.884157.2670.582136.356753378.0001270.450-0.001100753378.00025667159.83754.8832.5780.3880.948
two-nuclei.tif7378147.23031.77515083246327.123257.133327.459256.544333.99027920593104103.09091.124109.3390.831104.9381086261.0001470.183-0.5481001086261.00031920597.66792.8561.1310.8840.973

Your code ends before this line

run("Close");
print("batch measure nuclei finished");

> batch measure nuclei finished

The code below is for automatically checking the result. Please ignore it!

ok = (nImages==0);
ok = (ok && File.exists(path+"/out"));
files = getFileList(path+"/out");
ok = (ok && files.length==4);
if (ok)
	showMessage("That's right. Great, you did it!");
else 
	showMessage("Your result is wrong! Please check your macro and try again!");

Previous            Exercise            Next