Analyze Particles... overwrites last entry in results table?

For each frame of a film, my macro currently:

  1. Sets a threshold
  2. Combines all particles larger than 3 pixels (Set measurements, Analyze particles, Combine ROIs…)
  3. Measures an ellipse around the combined ROI and sends parameters to the results table

I would like to:
If no particles are found, add a line to the results table, indicating Area = 0: e.g. SetResults (Area, nResults, 0)

My problem:
If particles are found, any previous results from a frame where no particles were found is overwritten.

Any advice would be appreciated. Thanks! Attached is a sample film as well as the relevant code.


Original tiff: download

function makeMask() {
	ID = getImageID();
	run("Threshold...");
	setAutoThreshold("Default dark");
	setThreshold(38, 255);
	title = "Set the threshold";
	msg = "If necessary, use the \"Threshold\" tool to\nadjust the threshold, then click \"OK\".";
	waitForUser(title, msg);
	selectImage(ID);
	setOption("BlackBackground", false);
	run("Convert to Mask", "method=Default background=Dark");
}

function getParticles() {	
	for (j = 1; j <= nSlices; j++) {
		setSlice(j);
		run("ROI Manager...");
		roiManager("Show All"); //clears leftover ROI from previous frame if necessary;
		run("Set Measurements...", "area center display fit decimal=3");
		run("Analyze Particles...", "size=3-Infinity add slice");
		if(roiManager("count") == 0){	//this is the section with the problem;
			setResult("Area", nResults, 0);
		}
		if(roiManager("count") == 1){
			measureOneParticle();
		}
		if(roiManager("count") > 1){
			measureMultipleParticles();
		}
		if(roiManager("count") != 0){
			deleteROIs();
		}
	}
}

function measureOneParticle(){
	roiManager("Select", 0);
	roiManager("Measure");
}

function measureMultipleParticles(){
	selectAllROIs();
	roiManager("Combine");
	roiManager("Show None");
	roiManager("Add");
	ROIindex = roiManager("count") - 1;
	roiManager("Select", ROIindex);
	roiManager("Measure");
}

function deleteROIs(){
	selectAllROIs();
	roiManager("delete");
}

function selectAllROIs(){
	b = newArray(roiManager("count"));
	for (i=0; i<roiManager("count"); i++) b[i]=i;
	roiManager("select", b);
}
1 Like

Hello Phyo, did you figure it out? I don’t have any experience with the macro language myself. But… have you confirmed that this setResult("Area", nResults, 0); line works? That it actually adds a new row to the resultstable with a 0 area value?

Edit: I might have been wrong, I will look into this.

Yes, I was able to confirm earlier that the setResult(… line worked. It turns out that I was supposed to add updateResults(); after the setResult(…). Thanks!

1 Like