analyse_banana.ijm 1.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
// This ImageJ macro analyses a folder of 2D MRI 
// images showing a banana slice by slice. It measures
// the position of the banana and writes it in a CSV file.
//
// Usage: run it in Fiji (http://fiji.sc)
//
// Robert Haase, MPI CBG, rhaase@mpi-cbg.de
// April 2019
//

folder = "C:/structure/teaching/lecture_applied_bioimage_analysis/05_example_data/banana/" 

// access the folder
filelist = getFileList(folder);

for (i = 0; i < lengthOf(filelist); i++) {
	// get the nth entry from the filelist array
	file = filelist[i];
	
	if (endsWith(file, ".tif")) {

		// open the image
		open(folder + file);

		// segment the object in the image
		setAutoThreshold("Default dark");
		setOption("BlackBackground", true);
		run("Convert to Mask");
		run("Fill Holes");

		// measure the position of this one single object
		run("Set Measurements...", "centroid redirect=None decimal=3");
		run("Create Selection");
		run("Measure");

		// close the image
		close();
	}
}

// save the positions as CSV to disc
result_filename = "Position.csv"
saveAs("Results", folder + result_filename);