Handling script parameters


Before starting this lesson, you should be familiar with:

Learning Objectives

After completing this lesson, learners should be able to:
  • Organise script parameters in the code such that can be easliy adapted

  • Create dialog boxes for fetching script parameters


Scripts typically have parameters that one would like to change while leaving the core of the code untouched. Examples for such changable parameteres are the input image file and image processing parameters such as filter sizes and thresholds. It is very important to learn how to “expose” such parameters in ways that do not require digging into and modifying the actual code too much.

Concept map

graph TD S("Script") ---|has| P("Parameters") CB("Code block") --> P UI("UI elements") --> P CF("Config file") --> P A("Script arguments") --> P


Schematic code examples for how parameters may be stored inside or passed from outside to a script.


Show activity for:

Exposing script parameters: ImageJ Macro

  1. Download median_filter.ijm and open in Fiji.
  2. Identify the input parameters to be fetched
  3. Create parameter code block at the top of the script
  4. Write code to create a GUI to fetch these parameters


Download median_filter_solution.ijm

Interactive ROIs: ImageJ Macro

filePath = "https://github.com/NEUBIAS/training-resources/raw/master/image_data/xy_8bit__nuclei_noisy_small.tif"

// init
run("Close All");
run("Options...", "iterations=1 count=1 black do=Nothing");

// open

// draw background ROI
waitForUser("Please draw a background ROI");
getStatistics(area, mean, min, max, std, histogram);

// log background intensity
print("Mean background intensity: " + mean );


Show exercise/solution for:

Exposing script parameters: ImageJ Macro

  1. Download segment_nuclei.ijm and open in Fiji.
  2. Carefull examine the script and identify potential parameters.
    • Tip: There are up to 5 parameters.
  3. Replace all potential parameters by variables and define them in a code block at the top of the script
  4. Write code to create a GUI to fetch these parameters
    • Tip: In order not to define the varibales twice you need to remove (or better comment) the parameter code block that you just created.


Download segment_nuclei_solution.ijm



  1. Generally, what could be the pros and cons (considerations) of the different ways (see figure and concept map) in which scripting parameters can be handled?
  2. Specifically, what are the pros and cons of using UI elements for fetching parameters?


  1. This is a complex topic. Considerations could be: (i) How can I keep track which images were analyzed with which parameters? (ii) How can I ensure that users of my script use valid parameters? (iii) How experienced are the users of my script (e.g. would they be able to modify the script itself)? (iv) If the script itself is modified when changing a parameter, how do I keep track of the different “versions” of the script?
  2. Pro: UI elements typically allow you to restrict the input values to a valid range and it makes your script easy to use for people without programming experience. Con: Every time you want to run the script you have to interact with the UI and, unless you implement something special, you don’t keep track which parameters were used to run the script.

Follow-up material

Recommended follow-up modules:

Learn more: