0

I'm doing an imaging registration coding project that's way over my head. I do have code written by someone else I can adapt to my purpose, but I'm running into some issues. The code was written in Python, and I'm running it on my Mac in terminal. I've gotten some bits to work, and have my data files (the Image_1.tif files in the code) set up, but I get to a section of code that uses Elastix and I get an error. I don't know how to troubleshoot this. I've installed Elastix and I think I've added the folder containing it to my Terminal path.

The code is:

for movingIndex in range(1, range_limit):
    fixedImage = os.path.join(dataDir, "Image_1.tif")
    movingImage = os.path.join(dataDir, "Image_{0}.tif".format(movingIndex))
    affineRegDir = "affineRegistration_m{0}".format(movingIndex)
    affineResultDir = os.path.join(affineRegisteredDir, affineRegDir)
    if not os.path.exists(affineResultDir):
        os.makedirs(affineResultDir)
    elastixCommand = "elastix -f {0} -m {1} -out {2} -p {3} ".format(fixedImage, movingImage, affineResultDir,
                                                                     parameterFileAffine)
    subprocess.run(elastixCommand)

And when I try to run it I get the following error:

Traceback (most recent call last):
File "<stdin>", line 11, in <module>
  File "/Users/user_name/opt/anaconda3/lib/python3.9/subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/Users/user_name/opt/anaconda3/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Users/user_name/opt/anaconda3/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'elastix -f /Users/user_name/template_directory/data/Image_1.tif -m /Users/user_name/template_directory/data/Image_2.tif -out /Users/user_name/template_directory/affine_registered_data/affineRegistration_m2 -p /Users/user_name/template_directory/parameters/parameter_affine.txt '
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Alia
  • 1
  • Have you read the documentation of `subprocess.run` already? – mkrieger1 Jul 11 '22 at 22:13
  • Sorry, not sure what you mean by the documentation of it? – Alia Jul 11 '22 at 22:17
  • The website which explains what it does and how to use it. The manual. – mkrieger1 Jul 11 '22 at 22:25
  • @CodyGlickman That's not what the problem is. The problem is calling `subprocess.run` with a single string as argument, which is not the name of an executable. – mkrieger1 Jul 11 '22 at 22:27
  • Alia, in case you're still wondering about this "documentation", read it here: https://docs.python.org/3/library/subprocess.html#frequently-used-arguments – mkrieger1 Jul 11 '22 at 22:28
  • I'm voting to close this question as duplicate of [Python subprocess.Popen() error (No such file or directory)](https://stackoverflow.com/questions/30010939/python-subprocess-popen-error-no-such-file-or-directory) – mkrieger1 Jul 11 '22 at 22:30
  • Thanks for the help! I'll look through the subprocess manual. Just confused because this code was written by someone else who it apparently worked for, but I'll see what I can figure out from reading more. – Alia Jul 11 '22 at 22:37

0 Answers0