Skip to content

Instantly share code, notes, and snippets.

@GenevieveBuckley
Created January 9, 2018 04:52
Show Gist options
  • Save GenevieveBuckley/460d0abc7c1b13eee983187b955330ba to your computer and use it in GitHub Desktop.
Save GenevieveBuckley/460d0abc7c1b13eee983187b955330ba to your computer and use it in GitHub Desktop.
ImageJ API scripting in Jython - how to convert to and from ImgPlus and ImagePlus. http://javadoc.scijava.org
"""Converting from ImagePlus to ImgPlus.
When an ImagePlus is made available by ImageJ 1.x,
you can pass it to ImgLib2 as an Img via ImageJFunctions.wrap(imp)
http://javadoc.scijava.org/ImgLib2/net/imglib2/img/display/imagej/ImageJFunctions.html
"""
from ij import IJ
from net.imglib2.img import ImagePlusAdapter
image = IJ.openImage() # opens a file picker, or you can add the filename string as an argument.
output = ImagePlusAdapter.wrapImgPlus(image) #
output.show()
"""Wrap any Img as an ImgPlus."""
from net.imagej import ImgPlus
imgplus = ImgPlus(img)
# @Dataset img
"""Converting from ImagePlus to ImgPlus.
When an ImgLib2 RandomAccessibleInterval needs to be passed to ImageJ 1.x, it can be wrapped into an ImagePlus via ImageJFunctions.wrap(img, title).
"""
from net.imglib2.img.display.imagej import ImageJFunctions
output = ImageJFunctions.wrap(img, "title") # wraps the ImgPlus as an ImagePlus
output.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment