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();
	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);
	setOption("BlackBackground", false);
	run("Convert to Mask", "method=Default background=Dark");

function getParticles() {	
	for (j = 1; j <= nSlices; 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){
		if(roiManager("count") > 1){
		if(roiManager("count") != 0){

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

function measureMultipleParticles(){
	roiManager("Show None");
	ROIindex = roiManager("count") - 1;
	roiManager("Select", ROIindex);

function deleteROIs(){

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