5

EDIT NOTE: This question was originally phrased as

How to link SimpleITK.Show() to imageJ in linux?

By upgrading SimpleITK 1.0.0 to 1.0.1, I was able to launch ImageJ from SimpleITK.Show(). However, ImageJ is unable to open "sample_mri.hdr". ImageJ generates the following error messages.

File is not in a supported format, a reader

plugin is not available, or it was not found.

root/local/linux/ImageJ/open("/temp/TempFile-7131-2.nii");

root/local/linux/ImageJ/rename("/temp/TempFile-7131-2.nii");

I have installed the appropriate plugins for ImageJ to read hdr/img (Analyze format). I can open "sample_mri.hdr" from ImageJ directly by going to file>open

debug messages:

sitk.Show(img, 'sample image', debugOn=True)

FindApplication search path: [ ./Fiji.app, /cis/home/vwang/bin/Fiji.app, ~/bin/Fiji.app, /opt/Fiji.app, /usr/local/Fiji.app ]

Result:

FindApplication search path: [ ./Fiji.app, /cis/home/vwang/bin/Fiji.app, ~/bin/Fiji.app, /opt/Fiji.app, /usr/local/Fiji.app ]

Result:

FindApplication search path: [ ./ImageJ, /cis/home/vwang/bin/ImageJ, ~/bin/ImageJ, /opt/ImageJ, /usr/local/ImageJ ]

Result:

FindApplication search path: [ ./, /cis/home/vwang/bin/, ~/bin/, /opt/, /usr/local/ ]

Result: /usr/local/bin/ImageJ

Show command: '/usr/local/bin/ImageJ' '-e' 'open("/tmp/sample-4434-0.nii"); rename("sample");'

plugins:

How to link SimpleITK.Show() to imageJ in linux?

I've downloaded ImageJ and I can view images by running ImageJ directly. A similar question was asked and answered in the past (Can not "link"SimpleITK::Show() with FIJI), but the solution was for windows OS. What is the unix equivalent of

setx SITK_SHOW_COMMAND "C:\blah\blah\ImageJ\ImageJ.exe

My python code:

import SimpleITK as sitk

img = sitk.ReadImage("sample_mri.hdr")
sitk.Show(img, 'sample image')

Error message:

    return _SimpleITK.Show(*args, **kwargs)
RuntimeError: Exception thrown in SimpleITK Show: 
/tmp/SimpleITK/Code/IO/src/sitkShow.cxx:500:
sitk::ERROR: Error in administrating child process: [No such file or directory]
DottedGlass
  • 335
  • 3
  • 11
  • What version of SimpleITK are you using? Please try 1.0.1, as the error message should have improved. – blowekamp Aug 14 '17 at 20:55
  • I'm curious whether you have tried using the ImageJ ITK integration? http://imagej.net/ITK https://github.com/imagej/imagej-itk – ctrueden Aug 14 '17 at 21:25
  • @blowekamp I upgraded to 1.0.1, and I no longer get the error message at all. After running sitk.Show(), ImageJ launches, but I get two error messages (see edits). – DottedGlass Aug 16 '17 at 19:17

3 Answers3

3

On Ubuntu, I had the exact same problem, here is the solution:

  1. download http://imagej.net/Fiji
  2. unzip Fiji to home directory, ~/Fiji.app
  3. add this folder to your PATH

fiji will include all the plugins you need to display mri files, such as nifti and mha

1

SimpleITK is unable to find ImageJ. Try adding the debugOn=True parameter to the Show command. That will show you the search path it's using to try and find ImageJ.

So your Show would be the following:

sitk.Show(img, 'sample image', debugOn=True)

On Linux systems, SimpleITK searches the path for the following options: Fiji.app/ImageJ-linux64, Fiji.app/ImageJ-linux32, ImageJ/imagej, ImageJ, and imagej.

If your ImageJ executable is named something else, SimpleITK won't find it. I would suggest either soft linking to make it findable, or using the SITK_SHOW_COMMAND environment variable.

UPDATE: Not finding ImageJ was your original problem. I'm not sure about your update, but with the debugOn flag set, you can see the actual command line that SimpleITK is using to try and launch ImageJ.

Dave Chen
  • 1,905
  • 1
  • 12
  • 18
  • The executable is named ImageJ. I added the debug messages. – DottedGlass Aug 17 '17 at 15:41
  • As you can see, SimpleITK writes out a temporary image in Nifty format. IIRC some installations of ImageJ don't come with the Nifty I/O plugin. Can you see if you have the file nifty_io.jar in the plugins directory of ImageJ? If not, you can get it here: https://imagej.nih.gov/ij/plugins/nifti.html – Dave Chen Aug 17 '17 at 18:42
  • Another thing to try is the SITK_SHOW_EXTENSION environment variable. You could try setting it to ".mha". Then the temporary file will be written out in MHA format, which ImageJ might load better. We chose Nifty as the default because it supports the most pixel formats, but you can use any file format that ITK supports. More documentation about the Show function can be found here: https://itk.org/SimpleITKDoxygen/html/namespaceitk_1_1simple.html#ac8416e6e7f02dedfe8373b83dbea411d – Dave Chen Aug 18 '17 at 14:37
  • I've installed nifty_io.jar in the plugins directory. How do I set the SITK_SHOW_EXTENSION environment variable to ".mha"? I tried using "printenv" in the linux terminal but I couldn't find SITK_SHOW_EXTENSION. – DottedGlass Aug 25 '17 at 19:37
  • It is not set by default. If you're using the bash shell, it would be like this: export SITK_SHOW_EXTENSION=".mha" – Dave Chen Aug 28 '17 at 14:53
  • Running in the VS code debugger, ubuntu 19.10, I couldn't get ImageJ to run out of ~/bin, OR to display the path with debugOn=True. Not running out of ~/bin is a puzzler, because the ImageJ documentation could not possibly be clearer on this point. Only the environment variable worked for me. – J B Jul 28 '21 at 13:23
  • 1
    With SimpleItk 2.2.0 (python) you can also just print the executable names and expected paths with: `print(sitk.ImageViewer().GetGlobalDefaultExecutableNames())` `print(sitk.ImageViewer().GetGlobalDefaultSearchPath())` as well as the default file extensions: `print(sitk.ImageViewer().GetGlobalDefaultFileExtension()` – Paul Weibert Sep 05 '22 at 16:21
0

On Ubuntu, I did the following and it works:

  1. download http://imagej.net/Fiji
  2. unzip Fiji to home directory, unzip Fiji-download.zip -d ~/.
  3. add this folder to your PATH or Export path as: export SITK_SHOW_COMMAND="$HOME/Fiji.app/ImageJ-linux64" on your shell.

SimpleITK ought to find ImageJ without it, since it's in the expected location, but just try it out to see if it works.

susan097
  • 3,500
  • 1
  • 23
  • 30