Recorded-command only works for displayed images?

To call a command that was macro-recorded, is it necessary that the image is displayed on the screen ?
or is it enough to load it in memory with let say IJ.openImage() ?

Example:
Simple toy macro in scripts>Plugins>Test_.py

#@ImagePlus imp1
#@ImagePlus imp2
from ij import IJ

IJ.log( imp1.getTitle() )
IJ.log( imp2.getTitle() )

Once recorded the command is
run("Test ", "imp1=Head-WE10.tif imp2=Head-WE10.tif")
Here with the same image for both input but whatever.

Let’s try to call this command in a custom script

  • 1 - This works (images already opened)
#@ ImagePlus someImage1
#@ ImagePlus someImage2

from ij import IJ

args = "imp1={} imp2={}".format(someImage1.getTitle(), someImage2.getTitle() )
print args
IJ.run("Test ", args )
  • 2 - This does not work (opening the image in the code). -> imp1 is unset and required
    Eventhough the command call is properly formated
from ij import IJ

someImage1 = IJ.openImage(r"MyPath\Image.jpg")
someImage2 = IJ.openImage(r"MyPath\Image2.jpg")

args = "imp1={} imp2={}".format(someImage1.getTitle(), someImage2.getTitle() )
print args
IJ.run("Test ", args )