[ImageJ-devel] Simple usage of ImageJ2 and ImgLib2

Stephan Preibisch preibisch at mpi-cbg.de
Mon Jul 16 09:15:48 CDT 2012


Hi Padraig,

the ImageJFunctions is part of the imglib2-ij.jar package which you need to import ... this is, however, the ImageJ1 way to display ImgLib2 data, so we are not so sure that is what you are interested in. Maybe Curtis or Johannes could help?

Btw, if you are interested in getting a planar image (like each slice is a byte[], short[], float[], double[], etc.) you should use the PlanarImgFactory< T > which returns a PlanarImg<T, A>. It has a method "A getPlane(int planeNo)" which will return "A", i.e. the FloatArray, ByteArray, DoubleArray, ... containing the array for the respective plane. Each "A" has a method called "Object getCurrentStorageArray()", if it is a float-image it will be the "FloatArray" returning you float[]. Here is an example:

		// open image as float (returns an ImgPlus which has a PlanarImg)
		ImgPlus< FloatType > imgFloat = new ImgOpener().openImg( file.getAbsolutePath(),new PlanarImgFactory< FloatType >(), new FloatType() );
		
		// cast it to the right type of the PlanarImg
		PlanarImg< FloatType, FloatArray > planarImg = (PlanarImg< FloatType, FloatArray >)imgFloat.getImg();  

		// get plane number 0 (first plane)
		final float[] values = planarImg.getPlane( 0 ).getCurrentStorageArray();

Hope this helps,
Stephan and Tobias


On Jul 16, 2012, at 4:13 , Padraig Looney wrote:

> Dear list,
> 
> Apologies if this posting is not in the correct place but I seem to have hit a brick wall in moving to ImgLib2 and ImageJ2.
> 
> I have used ImageJ 1 without the the user interface for a variety of software projects. In Image J to open an Image I would use
> 
> Opener opener = new opener();
> Imageplus imp = opener.openImage("someFile");
> imp.show();
> 
> and from there I could perform the processing and change the display etc. 
> 
> With a view to moving to imgLib2 and ImageJ2 I have been going through the Javadoc to try to display an image perform more complicated tasks. So I have found this example among others on the Imglib2 site but in the imgLibs package there is no ImageJFunctions anymore.
> 
> public < T extends RealType< T > & NativeType< T > > Example1b()
>         throws ImgIOException, IncompatibleTypeException
>     {
>         // define the file to open
>         File file = new File( "DrosophilaWing.tif" );
>  
>         // open with ImgOpener using an ArrayImgFactory, here the return type will be
>         // defined by the opener
>         // the opener will ignore the Type of the ArrayImgFactory
>         ImgFactory< ? > imgFactory = new ArrayImgFactory< T >();
>         Img< T > image = new ImgOpener().openImg( file.getAbsolutePath(), imgFactory );
>  
>         // display it via ImgLib using ImageJ
>         ImageJFunctions.show( image );
>  
>         // open with ImgOpener as Float using a CellImgFactory, it will be opened as float 
>         // independent of the type of the image
>         // to enforce to open it as FloatType, an instance of FloatType has to be passed along
>         Img< FloatType > imageFloat = new ImgOpener().openImg( file.getAbsolutePath(),
>             new CellImgFactory< FloatType >( 10 ), new FloatType() );
>  
>         // display it via ImgLib using ImageJ
>         ImageJFunctions.show( imageFloat );
>     }
> 
> Ideally I would like to use Swing and get a Canvas containing the image and to be able to put this on a JFrame. I have gone through the ImageJ2 javadoc and I have found a range of classes that seem relevant such as Defaultdataset, SwingSdiImageDisplayViewer, SwingDisplayPanel but I keep running into errors with Services that don't exist because I am probably not using ImageJ2 as intended. 
> 
> Many thanks 
> 
> Padraig Looney
> Medical Physicist  
> Royal Surrey County Hospital
>  
> 
> 
> 
> _______________________________________________
> ImageJ-devel mailing list
> ImageJ-devel at imagej.net
> http://imagej.net/mailman/listinfo/imagej-devel




More information about the ImageJ-devel mailing list