Saving Pictures in bulk

So, I am writing a macro which uses one reference picture to find a circle. This circle is then automatically applied to a folder of single images, their threshold is set and basically the %Area is then saved in a .txt file. Now, in addition to that I need all of the single pictures to also be saved with the circle and threshold set in a .tif file in a output directory of my choosing. The way I am trying to do this doesn’t seem to work for me. Any ideas what I could change?

‘’’
//Referenzdurchlauf
//****************************************************************************************
run(“Set Measurements…”, “area_fraction display redirect=None decimal=3”);
run(“Find Edges”);
setThreshold(48, 255);
setOption(“BlackBackground”, true);
run(“Convert to Mask”);
run(“Hough Circle Transform”,“minRadius=50, maxRadius=300, inc=1, minCircles=1, maxCircles=1, threshold=0.2, resolution=1000, ratio=1.0, bandwidth=10, local_radius=10, reduce show_mask results_table”);
showMessage(“Press, when measurement is complete.”);
close(“Centroid overlay”);
run(“Revert”);
width = 2* getResult(“Radius (pixels)”);
height = width;
x = getResult(“X (pixels)”) - width/2;
y = getResult(“Y (pixels)”) - width/2;
x_original = getResult(“X (pixels)”);
y_original = getResult(“Y (pixels)”);
print(" X = “+x_original+”\n", “Y = “+y_original+”\n”, "Radius = "+width/2);
//****************************************************************************************

//Input Directory Auswahl (sucht nach Dateiendung)
//****************************************************************************************
#@ File (label = “Input directory”, style = “directory”) input
#@ File (label = “Output directory”, style = “directory”) output
#@ String (label = “File suffix”, value = “.tif”) suffix
//****************************************************************************************

//Ordner Funktion (Durchsucht Ordner und Unterordner nach Dateien mit definierter Endung)
//****************************************************************************************
processFolder(input);
function processFolder(input) {
list = getFileList(input);
list = Array.sort(list);
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]);
}
}
//****************************************************************************************

//Funktion, die auf alle Bilder angewandt wird
//****************************************************************************************
function processFile(input, output, file) {
open(file);
makeOval(x, y, width, height);
setThreshold(0, 80);
saveAs(“tiff”, “output”);
run(“Measure”);
run(“Close”);
}
//****************************************************************************************

//Speichert Messwerte in Datei
//****************************************************************************************
saveAs(“Results”);
//****************************************************************************************
‘’’

Hi,

what do you mean by not working?

One thing I guess you need to change is the saving with a specific name.

Thus I would get the filename or title and use that to save the image and the results such as:

title = getTitle();
saveAs("Tiff", output + title + ".tif");

alternatively you can also make new subdirectories using the file functions:
https://imagej.nih.gov/ij/developer/macro/functions.html

path = output + File.separator + title;
File.makeDirectory(path);
1 Like