/* AppendFourthChannel_1a.txt N. Vischer, 08.08.19, 13:38 https://sils.fnwi.uva.nl/bcb/objectj/examples/Coli-Inspector/utils/ To all images with 3 channels in chosen directory, a 4th channel is appended, and the changed file is saved. */ macro "Add Fourth Channel to all TIFFs"{ if(nImages > 0) showMessageWithCancel("Close All without saving?"); run("Close All"); print("\\Clear"); dir = getDirectory(""); print(dir); files = getFileList(dir); nFiles = files.length; count = 0; for(img = 0; img < nFiles; img++){ name = toLowerCase(files[img]); if(endsWith(name, ".tif") ||endsWith(name, ".tiff")){ open(dir+name); Stack.getDimensions(width, height, channels, slices, frames); if(channels == 3){ setSlice(3); run("Add Slice", "add=channel"); setSlice(1); run("Save"); print(++count, ": ", name); } close; } } if(count == 0) print("No files were changed"); else print("-- To ", count, " of ", nFiles, " files, a fourth channel was added --"); selectWindow("Log"); }