RunImageJMacro - CellProfiler/CellProfiler GitHub Wiki

The RunImageJMacro module provides the functionality to send images to an ImageJ/Fiji macro script and provide any resulting images from the macro back into the CellProfiler pipeline for further analysis.

ImageJ executable directory

The RunImageJMacro module assumes that a ImageJ/Fiji executable is already installed on the user's machine. For MacOS users, this corresponds to the Fiji.app application. Windows users should select the path to the ImageJ.exe executable.

A necessary directory parameter

It is assumed that the macro expects a string parameter, which will be used by ImageJ's open() and save() functions, for example:

#@String directory

from ij import IJ
import os

im = IJ.open(os.path.join(directory, 'dummy.tiff'))
IJ.run("Invert")
im2 = IJ.getImage()
IJ.saveAs(im2,'tiff',os.path.join(directory,'inverseddummy.tiff'))

The name of this parameter is up to the user. In this example, the parameter was named directory. Thus in this case, directory would be entered in the RunImageJMacro's input field named "What variable in your macro defines the folder ImageJ should use?". If the input variable had been named to path, the RunImageJMacro would have entered path in the "What variable in your macro defines the folder ImageJ should use?" text field.

Note: The user is not responsible for writing or reading images from that directory. In the background, CellProfiler will save its images in a temporary folder and set the directory (or whatever name is used by the macro) parameter to this temporary folder. Similarly, all images will be written to this temporary folder created by CellProfiler. All the user is responsible for is to specify the name of the parameter expected by open() and save() in the macro.

Specifying the input image filenames

After selecting the CellProfiler image that should be provided to the macro, the user will be prompted to enter a value for "What should this image temporarily saved as?". In the macro example above, it is expected that a dummy.tiff will live in the folder temporarily created by CellProfiler. Thus in this case, the user should enter dummy.tiff. CellProfiler will then know that the selected image should be saved under that name for the macro to successfully load the image.

Note that the user can select as many CellProfiler images as necessary. For each image, the corresponding filename expected by the macro should be specified.

Specifying the output image filenames

Finally, the user should enter the name of any image files written by the macro. In the example above, the user would enter inverseddummy.tiff as "What is the image filename CellProfiler call the loaded image?". In addition, a variable name corresponding to the resulting CellProfiler image should be entered in "What should CellProfiler call the loaded image?". The resulting image will be available to be used by the subsequent CellProfiler modules in the pipeline.

Macro parameters

All other macro parameter names and corresponding values can be entered in RunImageJMacro by clicking on the Add another variable button next to "Does your macro expect macro variables?". The user will then be prompted to enter the parameter name that a macro expects and its corresponding value. Note that the module will send variables in string format, but the declaration in the macro itself can parse them into other types, e.g. #@Integer myintvariable in the macro will consider the parameter as a whole number. Take care with this, since ImageJ may ignore delivered parameters if the incoming value could not be interpreted as the stated type.