Skip to content

Instantly share code, notes, and snippets.

@jeffapderek
Created April 1, 2019 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffapderek/97ac3c8a99be117d4fad390a3c67eaa9 to your computer and use it in GitHub Desktop.
Save jeffapderek/97ac3c8a99be117d4fad390a3c67eaa9 to your computer and use it in GitHub Desktop.
Batch processing particle images
/*
* Macro template to process multiple images in a folder
*/
#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix
// See also Process_Folder.py for a version of this code
// in the Python scripting language.
processFolder(input);
// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
setBatchMode(true)
list = getFileList(input);
list = Array.sort(list);
for (i = 0; i < list.length; i++)
action(input, output, list[i]);
setBatchMode(false){
if(File.isDirectory(input + File.separator + list[i]))
processFolder(input + File.separator + list[i]);
if(endsWith(list[i], suffix))
processFile(input, output, list[i]);
}
}
function action(input, output, file) {
open(input + File.separator + file);
title = getTitle();
run("Copy");
close();
newImage("Untitled", "8-bit black", 1000, 1000, 1);
selectWindow("Untitled");
run("Paste");
selectWindow("Untitled");
saveAs("Tiff", output + File.separator + "cropped_" + file);
print("Processing: " + input + file);
print("Saving to: " + output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment