Macro Error: There are no images open

Dear All,

I am very new to ImageJ. I am trying to open and renaming an image in a macro file. The image is already kept in proper folder in ubuntu.

I tried to run the below command from the command prompt:

./ImageJ-linux64  -batch /media/Reconstruct/Seg_linux/stitching_normalization.ijm "/media/Reconstruct/Seg_linux/Image" 

where stitching_normalization.ijm is my macro and Image is my image that I am trying to analyse.

In the macro I have:

run("MHD/MHA...", "open="+args[0]+"_top.mhd");
rename("top");

And I am having error:

Macro Error: There are no images open in line <line number>
<rename> ( "top" ) ;

Does anyone face something similar problem as mine? Could you please help me what might be the reason for that? Will I have to add any other plugins to run it successfully?

Thanks in advance.

Manisa

1 Like

You are trying to execute a script headlessly. You need to execute this in a particular way in ImageJ: https://imagej.net/Headless

But this might not work for certain ImageJ1 functions. So this might be the reason it fails.

Do you need to execute the macro in headless? You can just run it in the macro editor instead. https://imagej.nih.gov/ij/docs/guide/146-14.html

1 Like

Hi,

Thanks for your quick reply and support. I tried with headless from the command line but still I am facing the same problem:

Macro Error: There are no images open in line

( “top” ) ;

Should I download any required plugin for “MHD/MHA…” to run
the below commands from the script/macro?

**run(“MHD/MHA…”, “open=”+args[0]+"_top.mhd"); **
rename(“top”);

Thanks for your help.
Manisha

I tested it now using this macro:

arg = getArgument();
run("MHD/MHA...", "open=" + arg);
rename("top");
saveAs("Tiff", "/home/schmiedc/Desktop/top.tif");

using this command prompt:

./ImageJ-linux64 --headless --console -macro /home/schmiedc/Desktop/test.ijm /home/schmiedc/Desktop/test1.mha

using ubuntu with ImageJ 2.0.0-rc-69/1.52p

this works. My guess is the way you supply the arguments is not correct or the filename is not correct and the image is not found or opened.

Hi All,

I tried with

./ImageJ-linux64  --headless --console -macro /media/Reconstruct/Seg_linux/stitching_normalization.ijm "/home/rcollier/imageprocessing/images/Image" 

and in the macro, we have the code for appending the _top.mhd with the name of the argument, that is
/home/rcollier/imageprocessing/images/Image. Still having the same problem,

Macro Error: There are no images open in line
( “top” ) ;

and the image is present. I am guessing that that run command will open the image as it was given like run("MHD/MHA...", "open="+args[0]+"_top.mhd"); in the macro.

I am running this code by remote logging to the server, not in my machine directly.

One more question: How to check the version of the ImageJ in the command line in ubuntu. From README.md file, I see that the version of ImageJ is 2.35. Is this correct way to check the version of ImageJ in ubuntu?

Could you guys help me? And thanks for your support.

Please use print statements to verify that your variables contain what you think they do.
You can save the log file using:

selectWindow("Log");
saveAs("Text", "/Path/to/Directory/Log.txt");

You can execute the following commands in a macro to check ImageJ version and java version:

getInfo("java.version");
getInfo("os.name");
getVersion();
IJ.getFullVersion;
IJ.maxMemory();