Append measurements to an csv table

Hi,

I looked through the net and here and didn’t find what I was looking for. I know that you can import results, and then they’ll appear into the results panel, but when I do a measurements afterward, ImageJ wants to save those already existing measurements and save the new measurements into a new file.

How can I append measurements to an existing file directly in Fiji (ImageJ), instead of each time creating a new file ?

Thank you very much and I am sorry if this was already answered, I just didn’t found it.

@klopfy

For me… the new results are appended to the existing table.

These are the exact steps I used to do this:

  1. Setting up my test image/objects… (Open Samples > Blobs; Threshold (Default settings); Create Mask; Analyze Particles (saving to ROI Manager))
  2. Then… when I Measure - a Results table appears with all my measurements
  3. Save As... .csv file format…
  4. Close the Results table…
  5. File, Import, Results and open my saved measurements
  6. if I Measure again with that window open - the results are appended

What are the exact steps you are using in your workflow?? Are you doing this via a macro?

eta

@etadobson

I import my .csv table (drag and drop), then open a file (drag and drop also), selection a line and hit measure.
Then Fiji prompts me if I want to save the previously opened table and saves the measurements in a new table, and thus a new file.

@klopfy

I was able to recreate this ‘issue’ that you are having… perhaps we can do a work-around? What is your overall analysis workflow? Would you be able to batch process it? Below is an example code that counts nuclei and constantly appends the results table (it is a part of the Scripting Workshop)… individual results tables can also be saved instead with some modifications to the code.

Perhaps if we just take a step back - we can better streamline your whole pipeline.

eta

/*
* Macro to count nuclei in multiple images in a folder/subfolders.
*/

#@File(label = "Input directory", style = "directory") input
#@File(label = "Output directory", style = "directory") output
#@String(label = "File suffix", value = ".tif") suffix
#@int(label = "Minimum size") minSize

processFolder(input);
	
// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
	list = getFileList(input);
	for (i = 0; i < list.length; i++) {
		if(File.isDirectory(input + File.separator + list[i]))
			processFolder("" + input + File.separator + list[i]);
		if(endsWith(list[i], suffix))
			processFile(input, output, list[i]);
	}
	//saves results for all images in a single file
	saveAs("Results", output + "/All_Results.tsv"); 
}

function processFile(input, output, file) {
	setBatchMode(true); // prevents image windows from opening while the script is running
	// open image using Bio-Formats
	run("Bio-Formats", "open=[" + input + "/" + file +"] autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
  id = getImageID(); // get original image id
	run("Duplicate...", " "); // duplicate original image and work on the copy
	
	// create binary image
	run("Gaussian Blur...", "sigma=2");
	setAutoThreshold("Default dark");
	//run("Threshold...");
	run("Create Mask");
	run("Watershed");
	// save current binary image
	save(output + "/Binary_OUTPUT_" + file);
	
	run("Analyze Particles...", "size=" + minSize + "-Infinity exclude add");
  selectImage(id); // activate original image
  roiManager("Show All with labels"); // overlay ROIs
	roiManager("Deselect");
	roiManager("Measure"); // measure on original image
	
	// save ROIs for current image
	roiManager("Deselect");
	roiManager("Save", output+ "/" + file + "_ROI.zip"); // saves Rois zip file
	roiManager("Deselect");
	roiManager("Delete"); // clear ROI Manager for next image
}

@etadobson

Thank you for your answers. For my work I have to measure different length on pictures of fishes, and I am not using a macro on Fiji. I guess that I will have just to do with that ‘issue’ which is just a bit annoying. I was surprised that it was not possible to do something that simple and trivial as appending measure to an existing table without using the ROI manager.

The simple solution is to concatenate the results of my session to my already existing table, which is just a simple command on a terminal.

Maybe one could propose to fix this to the development team. ( I mean, if you can import a result table but not use it when measuring something new, what’s the point of importing at all ? )
But as you said, this is fixed when using the ROI manager, I guess, so I’ll try using that.

1 Like

I’m sure by now this has already been resolved but in case anyone needs to do this in the future, Read and Write Excel plugin allows for an argument (stack_results) that lets you, as the name suggests, stack results i.e append to the same file. You can also queue results to be saved as you generate them then save everything at the end to the same file.