Macro, opening and saving issues

imagej
macro

#1

Hello guys,

first of all I gotta say its my very very first time trying to write a macro in FIJI.

My macro is supposed to measure simply the area and the amount of particals from my images. As I have different sets of images with different objects, its important to set the threshold by myself. This i successfully implemented.

I have two other issues though:

First of all my macro only allows me to only process one image at a time. I would love to run the macro directly over a whole folder.

Second, my biggest issue lies in saving my data. I have two different tables generated: “Summarize” and “display results”. I would love to be asked where to save it and how to call the generated file for both of them individually.

Here is my macro:

file=File.openDialog("select image")
print(file)
open(file);
run("Threshold...")
waitForUser("Set the threshold, then press ok")
//run("Threshold...");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Set Measurements...", "area display redirect=None decimal=3");
run("Analyze Particles...", "summarize + display results");
dir = getDirectory("choose where to save the summary"); 
run("Measure"); 
name = getTitle; 
dotIndex = indexOf(name, ".");  
saveAs("Results", name + ".csv");  
close()

#2

Good day,

most of your questions have been discussed many times here on the Forum. They are really standard.

Additionally please consult the commented list of ImageJ-macro functions:
https://imagej.nih.gov/ij/developer/macro/functions.html

Here you find a long list of helpful sample macros:
https://imagej.nih.gov/ij/macros/

Please have a look especially at
https://imagej.nih.gov/ij/macros/BatchProcessFolders.txt
which deals with “folder processing”.

Setting thresholds by hand is not recommended for scientific purposes. It leads to results that are hardly reproducible. Always use one of the automatic threshold schemes. If this appears impossible, you need to pre-process your images accordingly.

Regards

Herbie


#3

In addition to the page Herbie linked to, there’s also Batch Processing on the wiki, detailing a few more options:

The most recent addition (which isn’t so well documented yet, due to lack of time) is the Batch button in the script editor. If you replace the first line (File.openDialog()) in your macro by a script parameter, such as:

#@ File (label="select image") file

… you’ll be able to run your script with the Batch button and it will run the macro for each file selected as input.