Overviewimglib2 appears to be a very powerful image analysis library. It's targeted at folks who do complicated image processing such as scientific analysis and medical-image analysis. I'm starting to use it for some relatively simple analysis. The learning curve for it is pretty steep. As an example, imglib2 has a types heirachy. In this case, 'types' are classes used to retrieve a value from an image. There's a mere 35 classes and interfaces involved in the type hierachy. Since these types appear everywhere in imglib2, you'll have to grok them inorder to even just get started reading an image. imglib2 provides the ImgOpener class for reading image data. I'm currently trying to use it to read both black and white tiffs as well as the more common jpg and png formats. ImgOpener has a few quirks that I'm going to make mention of. NOTE: my examples are written in Scala, apologies to the Java folks
Read and Ignore Types
val tiff = "blackandwhite.tiff" val jpg = "color.jpg" import net.imglib2.io._ val io = new ImgOpener val tiffImgPlus = io.openImg(tiff) val jpgImgPlus = io.openImg(jpg)both the tiff and jpg are read in correctly but appear in Scala as ImgPlus[Nothing]. The underlying Img implementation for both are PlanarImg
Read Using Correct TypeIn order, to enforce the type, you need to pass the correct instance of the type into the openImg method. The tiff should be read as a ShortType.
val tiff = "blackandwhite.tiff" import net.imglib2.io._ import net.imglib2.`type`.numeric.integer.ShortType val io = new ImgOpener val tiffImgPlus = io.openImg(tiff, new ArrayImgFactory[ShortType], new ShortType)The jpg should be read as an UnsignedByteType
val jpg = "color.jpg" import net.imglib2.io._ import net.imglib2.`type`.numeric.integer.UnsignedByteType val io = new ImgOpener val jpgImgPlus = io.openImg(tiff, new ArrayImgFactory[UnsignedByteType], new UnsignedByteType)When an image is read this way, the underlying Img implementation is an ArrayImg.
Read Using an Incorrect TypeIf you specify the wrong factory with out passing in a type, ImgOpener will still go ahead and open the image as a PlanarImg
val tiff = "blackandwhite.tiff" import net.imglib2.io._ val io = new ImgOpener // Should be ShortType but using incorrect ARGBType val tiffImgPlus = io.openImg(tiff, new ArrayImgFactory[ARGBType])Now the underlying image is once again a PlanarImg.