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!
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");
run()calls are available in the scripting languages by using
IJ.run(), so in Jython, this would look like:
from ij import IJ IJ.run("Raw...", "open=[/path/to/your/image.raw] image=8-bit width=4000 height=2672 number=40 little-endian")
The drawback here is that in order to retrieve the image into an
ImagePlusvariable, 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.
BeanShellmode, 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 = Raw.open("/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 ij.io 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 = Raw.open("/path/to/your/image.raw", fi)
Hope that helps
Thanks. This will definitely be helpful.