Measuring Skeletonized Axons

This part of a ImageJ Macro skeletonizes and measures Axons from Images acquired via Bright Field Microscopy. It goes through a Folder and processes all Images in that Folder. The Results are then exported as a .txt file.

My questions:

  1. I would appreciate an explanation of the measuring process.
  2. Instead of giving me one Result (which is the sum total length of all skeletonized pieces/ per Image) I need the software to export Results (lengths) for each Individual skeletonized piece, in every Image. Meaning, I would have lots of measurements per Image instead of one Result/Image.
    Thanks for your help!

Source Code:

//Skeletonize.
	print("Creating tracings...");
	selectImage("Thresholded Green");
	//run("Invert", "stack");
	run("Skeletonize", "stack");
	//run("Dilate", "stack");
	open(dir+"Neuronal Nuclei.tif");
	imageCalculator("Subtract create stack","Thresholded Green","Neuronal Nuclei.tif");
	setThreshold(255, 255);
	run("Threshold", "thresholded remaining black stack");
	run("Colors...", "foreground=white background=black selection=yellow");
	run("Particle Remover", "size=0-100 circularity=0.50-1.00 show=Nothing stack");
	run("Colors...", "foreground=black background=white selection=yellow");
	rename("Skeletonized Green");
	setThreshold(255, 255);
	run("Threshold", "thresholded remaining black stack");
	selectImage("Neuronal Nuclei.tif");
	close();
	selectImage("Thresholded Green");
	close();

	//Refine tracings: remove dirt
	run("Particle Remover", "size=0-25 circularity=0.10-1.00 stack");
	print("Tracings Refined, dirt removed!");
	
	//Measure traces and count nuclei
	print("Measuring tracings and counting neurons...");
	run("Clear Results");
	
	selectImage("Skeletonized Green");
	saveAs("tiff", dir+"tracings.tif");
	setBatchMode(true);
	selectImage("tracings.tif");
	length=newArray(nSlices+1);
	for (i=1;i<nSlices+1;i++){
		setSlice(i);
		run("Select All");
		run("Copy");
		run("Internal Clipboard");
		run("Lines8 ", "white show=Lines minimum=0 maximum=9999999 display redirect=None");
		selectWindow("Results");
		text = getInfo();
		lines = split(text, "\n");
		columns = split(lines[0], "\t");
		
		if (columns[0]==" ")
			columns[0]= "Number";
			param=newArray(nResults);
			dmax=-1000000000;
			dmin= 1000000000;
			 tot=0;
			ave=0;
			nc=nResults;
			hasmin1=false;
			for (j=0; j<nResults; j++) {
				data1=getResult(columns[7], j);
				if (data1==-1)
				nc--;
			else{
				if(data1==-1) hasmin1=true;
				if (data1>dmax) dmax=data1;
				if (data1<dmin) dmin=data1;
				tot+=data1;
			}
		}
		length[i]=tot/scale;
	selectImage("Clipboard");
	close();
	selectWindow("Results");
	run("Close");
	}
	
	for (i=1; i<nSlices; i++) {
	    setSlice(i);
		label=getMetadata();
		setResult("Label",i-1,label);
		setResult("Length",i-1,length[i]);
	}
	updateResults();
	selectWindow("Summary of Neuronal Nuclei");
	nucleisummary = split(getInfo(),'\n');
	for (i=1; i<nSlices; i++) {
		foo = split(nucleisummary[i]);
		setResult("Nuclear Count",i-1,foo[1]);
	}
	updateResults();
	
	selectWindow("Results");
	saveAs("measurements", dir+"measurements_"+File.getName(dir)+".txt");
	print("Done!");