Batch processing images and saving to txt file

Hi, I’m a new coder to imageJ, I’m not having success printing the centroid result to file at the moment. Any suggestions would be greatly appreciated…Currently the first centroid x,y result is saved to the Results, but the remaining ones fail.

  dir = getDirectory( "Choose the Directory" );
  list = getFileList( dir );
   for ( i=0; i<list.length; i++ ) {
   open( dir + list[i] );
    }
   
   //setBatchMode(true);
   count = 0;
   countFiles(dir);
   n = 0;
   processFiles(dir);
   print(count+" files processed");
   
  
   function countFiles(dir) {
      list = getFileList(dir);
      for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
              countFiles(""+dir+list[i]);
          else
              count++;
        }
    }
	
   function processFiles(dir) {
      list = getFileList(dir);
      for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
              processFiles(""+dir+list[i]);
          else {
             showProgress(n++, count);
             path = dir+list[i];
             processFile(path);
          }
      }
  }

  function processFile(path) {
       if (endsWith(path, ".dcm")) {
           open(path);
           	setAutoThreshold("Shanbhag");
			setThreshold(0, 27310);
			setOption("BlackBackground", false);
			run("Convert to Mask");
			run("Analyze Particles...", "size=100-99999 circularity=0.6-1.00 exclude clear add");
			run("Measure");
			//roiManager("Add");
            //close();
      }
  }
  	  
	updateResults();  // Update the results table so it shows the filenames

	// Show a dialog to allow user to save the results file
	outputFile = File.openDialog("Save results file");
	// Save the results data
	saveAs("results",outputFile);

Just to note, this imageJ macro would be applied to multiple DICOM images.

Hi,
change your lines 45-48 to the following where I removed the clear and add (clears the results table and adds to ROI Manager) parameters and added the display parameter (for display results)
Jerome.

Many thanks Jerome! That sorted everything out, looks like I was being a little schizophrenic with my code…

Cheers!

1 Like