Image Processing Paper Java
Image Processing Paper Java
type, dimensionality and storage layout. Using ImgLib2, this can implementations using image factories. This allows performance
be written generically as tuning for specific datasets without any modification to the al-
gorithm implementation.
for (T value : image) sum.add(value);
We compared the performance of ImgLib2 generic code and
where we specify that image implements IterablehTi and that T special purpose (fixed dimensionality and value type) implemen-
extends NumericTypehTi. The same code handles all pixel images tations for Java primitive type arrays and ImageJ
with appropriate value type, virtual views into such images, spar- (Supplementary Table S1). For simple per-pixel operations, gen-
sely sampled datasets, procedural images, etc. eric ImgLib2 code achieves 100% of the performance of special
In Java, this level of generality requires pixels to be objects. purpose implementations using native arrays. For a more com-
Storing simple pixel values (e.g. bytes) as individual objects, how- plex operation involving an inner loop over the unknown
ever, comes with significant memory overhead. Conversely, number of dimensions, the ImgLib2 code was on average
creating new objects per pixel access introduces significant run- 1.6 slower than native arrays (1.5 slower than ImageJ). We
time overhead and triggers frequent garbage collection. Both consider this a reasonable abstraction penalty as the ImgLib2
approaches do not scale well with large images. To address this code supports any dimensionality, image and value type. In con-
issue, ImgLib2 uses proxy types to access pixel data that can be trast, native arrays and ImageJ images require specialized imple-
mapped into Java primitive type arrays (byte[], float[], etc.). In mentations for each supported dimensionality and value type.
this way, an accessor can re-use one proxy instance for all pixel For the cases tested in our benchmark, this amounts to an
accesses. In the above example, a proxy of type T is instantiated order of magnitude increase in lines of code. Even so, only
once and then re-used in every iteration, changing only internal ImgLib2 is able to handle all test cases due to dimensionality
state. This virtualization pattern has no performance overhead and image size limits of both ImageJ and primitive type arrays.
compared with direct array access, thanks to the optimizations ImgLib2 permits virtualization of sample access. We use
performed by Java’s just-in-time (JIT) compiler. this for accessors that perform on-the-fly coordinate and value
transformations without copying the underlying data. The
Views framework creates accessibles that provide coordinate-
3 IMPLEMENTATION transforming accessors. Integer coordinate transformations in-
ImgLib2 incorporates common value types (BitType, Unsigned- clude slicing, windowing, axes permutations and 90 rotations.
ByteType, ARGBType, ComplexFloatType, etc.) efficiently im- Consecutive transformations are reduced and simplified, yielding
plemented as proxies that map into Java primitive type arrays. accessors with optimal performance. For real coordinates we
Various implementations for pixel data in a discrete n-dimen- support n-dimensional affine transformations. Interpolating
sional grid (conventional pixel images) are provided: ListImg and rasterizing views convert between discrete and continuous
stores pixels as individual object instances and thus supports ar- coordinate spaces. Finally, some algorithms (e.g. convolution)
bitrary value types, but does not scale to large numbers of pixels. require access to pixels outside of the image which are usually
ArrayImg maps proxy types into a single primitive type array, created by padding or mirroring. This is achieved by extending
providing optimal performance and memory efficiency. views, whose accessors generate outside values on demand. Note,
However, Java arrays are limited to a size of 231 (e.g. a square that views may be cascaded and act both as input and output for
2d image with maximally 46,340 px side length) which is easily pixel processing. Similarly, the Converters framework realizes
exceeded in today’s microscopy recordings. CellImg splits the transparent transformation of values. For instance, a
coordinate domain into an n-dimensional grid of cells, each map- FloatType image can be addressed as ByteType using an arbi-
ping into one primitive type array. This enables significantly trary mapping function.
larger images (262 px) at slightly reduced performance. In ImgLib2 uses Bio-Formats (Linkert et al., 2010) to read and
generic code we can transparently switch between image write a large number of image file formats. Interoperability with
3010
ImgLib2
ImageJ is provided by non-copying wrappers of ImageJ data microscopy. Consequently, ImgLib2 is already being used by
structures as ImgLib2 accessibles and vice versa. This makes it several high-profile projects of the Java bioimaging community
straightforward to integrate ImgLib2 into existing ImageJ-based (Berthold et al., 2009; Rueden et al., 2010; Schindelin et al.,
processing pipelines. Light-weight wrappers for other data 2012). It is easily integrated into other projects providing an
models are easy to implement and currently exist for Java ideal basis for sharing interoperable, generic algorithms.
AWT BufferedImage, Java primitive type arrays and remotely
stored image stacks (Saalfeld et al., 2009). ImgLib2 comprises
a growing collection of generic algorithms that are fundamental ACKNOWLEDGEMENTS
building blocks for n-dimensional image analysis: the Fast ImgLib2 and ImgLib have been supported by Fiji Hackathons
Fourier Transform can be used for tomography reconstruction, at the MPI-CBG, EMBL and LOCI. We gratefully thank all
pattern detection or (de-)convolution; sub-pixel edge detection
3011