LemnaGrid is a platform for image processing and analysis. It uses Ipp, opencv, and other libraries as backend along with propriatory algorithms and provides graphical interface to the user to access a wide range of useful tools. The functionality of LemnaGrid can be extended interacting with external image processing applications. In this short post I am going to show how three different external programs (ImageMagick, ImageJ, R/EBImage) can be embedded into the LemnaGrid workflow to perform fast fourier transform (FFT).

Introducing the external command processing interface

The External Command Processing device is the LemnaGrid tool to communicate with foreign applications.

Briefly this is accomplished in three steps:-

  • only bitmaps are used to exchange data between LemnaGrid and an external program
  • the call to the external tool is specified by the full filepath

command line options are provided

External Command Processing assumes that the external tool is invoked by: tool.exe OPTIONS INPUT.bmp OUTPUT.bmp

However if your favorite tool uses a different syntax, then you can create a .bat file and customise the command line parameters accordingly.

For example:

REM MS-DOS batch file

set opt=%1

set ii=%2

set oo=%3

convert %ii -blur 20 %oo

where convert is a command line tool from the ImageMagick software suite.

Fast Fourier transformation with ImageMagick

ImageMagick is a free and open-source software suite to create, edit, compose, or convert bimap images. Here I want to apply the fast fourier transform (fft) function and process the phase output image. I downloaded ImageMagick from blog.astrophotographytargets.com/2012/03/imagemagick-with-fftw-delegate-library-on-windoes and installed it in C:/imagemagick. Next I created and tested a batch script (C:\imagemagick\extcmd.bat) to call the fft function from ImageMagick:

REM MS-DOS batch file

“C:\imagemagick\convert.exe” %2 %1 out.bmp

copy out-1.bmp %3

With the sample image “stripes.bmp” I tested the batch script in the DOS terminal:

C:> C:\imagemagick\extcmd.bat -fft stripes.bmp stripes-output.bmp

Now it is time to call ImageMagick from LemnaGrid. First I loaded an input image with DBReader, and then I connect it with the External Image Processing device. I set the tool path to C:\imagemagick\exctcmd.bat, and typed “-fft” as command line option.

Combining ImageJ macro programming and LemnaGrid

ImageJ is a public domain, Java-based image processing program developed at the National Institutes of Health. ImageJ was downloaded from rsb.info.nih.gov/ij/download.html and I installed it under C:\ImageJ. Next I created an ImageJ macro file (C:\ImageJextcmd.ijm):

// ImageJ macro file

macro “extcmd” {


saveAs(“BMP”, getArgument());



and also the corresponding .bat file (C:\ImageJ\extcmd.bat):

REM MS-DOS batch file

“C:\ImageJ\Imagej.exe” %2 %1 C:\ImageJ\extcmd.ijm %3

Again I tested everything from the DOS terminal first before deploying it in LemnaGrid:

C:> C:/ImageJ\extcmd.bat -batch stripes.bmp stripes-output.bmp

The corresponding settings in External Image Processing are:-

  • tool path = C:\ImageJ\extcmd.bat
  • command line option = -batch

Linking LemnaGrid to the world of R/EBImage

R is a free software programming language and software environment for statistical computing and graphics. EBImage is an R package with general purpose functionality for processing and analysis of images in context of microscopy based cellular assays. I downloaded R from cran.r-project.org/bin/windows/base and installed it under C:\R. Next I installed the EBImage package by following the instructions from bioconductor (bioconductor.org/packages/release/bioc/html/EBImage.html). Then I developed and tested my R script (C:\R\extcmd.R):

### R script

args = commandArgs(TRUE)



i = Image(read.bmp(args[2]))

writeImage(fft(i), args[3])

The call to this R script is done with this .bat file (C:\R\extcmd.bat) :

REM MS-DOS batch file

“C:\R\bin\Rscript.exe C:\R\extcmd.R” %1 %2 out.png

“C:\imagemagick\convert.exe” out.png %3

Notice, I did not find out how to save an image as .bmp in R, so in the .bat file I had to do a file format conversion with ImageMagick. The R workflow was tested in the DOS terminal:

C:> C:\R\bin\extcmd.bat CMD stripes.bmp stripes-output.bmp

The corresponding settings in External Image Processing device are:-

  • tool path = C:\R\bin\extcmd.bat
  • command line option = CMD


If you want to use your own magic box within the LemnaGrid framework, then you use the External Image Processing device. Here I have listed three different command line based applications that integrate with LemnaGrid.