Opening raw file using IJ.openImage() function in Jython

I am totally new in ImageJ scripting. I want to use IJ.openImage() function with Jython script to import raw image, that is, besides passing the path to the file I want to pass parameters like
" imageType=8-bit", “width=4000”, “height=2672” offset=0 number=40 gap=0 little-endian" etc. Can somebody point me to the API description for IJ.openImage() method or exampleto do this?

Hi @supratik, and welcome to the forum!

The IJ.openImage(String) method doesn’t support additional parameters such as an option string.

You can however use the recorder to get your required sequence of commands:

  • in Macro mode, it’ll record something like this:

    run("Raw...", "open=[/path/to/your/image.raw] image=8-bit width=4000 height=2672 number=40 little-endian");

    All macro run() calls are available in the scripting languages by using, so in Jython, this would look like:

    from ij import IJ"Raw...", "open=[/path/to/your/image.raw] image=8-bit width=4000 height=2672 number=40 little-endian")

    :exclamation: The drawback here is that in order to retrieve the image into an ImagePlus variable, you’ll need to call:

    from ij import WindowManager
    imp = WindowManager.getCurrentImage()

    … which makes your script susceptible to race conditions when working with the UI in parallel to running the script.

  • in JavaScript or BeanShell mode, the recorder will record something like:

    fi = new FileInfo();
    fi.fileType = FileInfo.GRAY8;
    fi.width = 4000;
    fi.height = 2672;
    fi.nImages = 40;
    fi.intelByteOrder = true;
    imp ="/path/to/your/image.raw", fi);

    … which is the more robust way to open raw files from any scripting language. It translates to Jython as follows:

    from import FileInfo
    from ij.plugin import Raw
    fi = FileInfo()
    fi.fileType = FileInfo.GRAY8
    fi.width = 4000
    fi.height = 2672
    fi.nImages = 40
    fi.intelByteOrder = true
    imp ="/path/to/your/image.raw", fi)

Hope that helps :slightly_smiling_face:


Thanks. This will definitely be helpful.