Using Bio-Formats as a Java library¶
Bio-Formats as a Maven, Gradle or Ivy dependency¶
All released .jar
artifacts are published to and can be obtained from
the OME Artifactory. The
“Client Settings” section of the Artifactory main page provides example code
snippets for inclusion into your Gradle, Maven or Ivy project, which will
enable the use of this repository.
Examples of getting started with Bio-Formats using Maven or Gradle are given in the https://github.com/ome/bio-formats-examples repository. OMERO uses Ivy to manage its Java dependencies including Bio-Formats.
Note
In order to retrieve the NetCDF dependency of Bio-Formats, it is necessary
to configure the Unidata releases repository in addition to Maven Central and
the OME artifactory in your pom.xml, build.gradle or
ivy.xml
file.
Bio-Formats as a Java library¶
Alternatively Bio-Formats can be used by including its component jar files.
You can download formats-gpl.jar to
use it as a library. Just add formats-gpl.jar
to your CLASSPATH
or
build path. You will also need ome-common.jar
for common I/O functions,
ome-xml.jar
for metadata standardization, and
SLF4J for Logging.
Dependencies¶
The complete list of third-party dependencies for formats-gpl.jar is as follows:
Package |
Maven name |
License |
---|---|---|
ch.qos.logback:logback-classic:1.2.0 |
||
ch.qos.logback:logback-core:1.2.0 |
||
cisd:jhdf5:19.04.0 |
||
cisd:base:18.09.0 |
||
commons-io:commons-io:2.7 |
||
org.apache.commons:commons-lang3:3.10 |
||
com.adobe.xmp:xmpcore:5.1.3 |
||
com.beust:jcommander:1.27 |
||
com.drewnoakes:metadata-extractor:2.11.0 |
||
io.airlift:aircompressor:0.18 |
||
com.esotericsoftware.kryo:kryo:4.0.2 |
||
com.esotericsoftware:reflectasm:1.11.3 |
||
org.ow2.asm:asm:5.0.4 |
||
com.esotericsoftware.minlog:minlog:1.3 |
||
com.google.guava:guava:29.0-jre |
||
com.jgoodies:jgoodies-common:1.7.0 |
||
com.jgoodies:jgoodies-forms:1.7.2 |
||
commons-lang:commons-lang:2.6 |
||
commons-logging:commons-logging:1.1.1 |
||
edu.ucar:cdm:4.6.13 |
||
joda-time:joda-time:2.2 |
||
junit:junit:4.10 |
||
org.beanshell:bsh:2.0b4 |
||
org.hamcrest:hamcrest-core:1.1 |
||
org.objenesis:objenesis:2.5.1 |
||
org.perf4j:perf4j:0.9.16 |
||
org.scijava:native-lib-loader:2.1.4 |
||
org.slf4j:slf4j-api:1.7.6 |
||
org.testng:testng:6.8 |
||
org.yaml:snakeyaml:1.6 |
||
woolz:JWlz:1.4.0 |
||
xalan:serializer:2.7.2 |
||
xalan:xalan:2.7.2 |
||
xerces:xercesImpl:2.8.1 |
||
xml-apis:xml-apis:1.3.04 |
||
io.minio:minio:5.0.2 |
||
com.google.http-client:google-http-client-xml:1.20.0 |
||
com.google.http-client:google-http-client:1.20.0 |
||
xpp3:xpp3:1.1.4c |
||
com.squareup.okhttp3:okhttp:3.7.0 |
||
com.squareup.okio:okio:1.12.0 |
||
javax.xml.bind:jaxb-api:2.3.0 |
||
org.json:json:20090211 |
||
org.xerial:sqlite-jdbc:3.28.0 |
||
com.google.guava:failureaccess:1.0.1 |
||
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava |
||
com.google.code.findbugs:jsr305:3.0.2 |
||
org.checkerframework:checker-qual:2.11.1 |
||
com.google.errorprone:error_prone_annotations:2.3.4 |
||
com.google.j2objc:j2objc-annotations:1.3 |
||
edu.ucar:httpservices:4.6.13 |
||
org.apache.httpcomponents:httpclient:4.5.1 |
||
commons-codec:commons-codec:1.9 |
||
org.apache.httpcomponents:httpmime:4.5.1 |
||
com.mchange:c3p0:0.9.5.3 |
||
com.mchange:mchange-commons-java:0.2.15 |
||
com.fasterxml.jackson.core:jackson-core:2.9.8 |
||
com.fasterxml.jackson.core:jackson-annotations:2.9.8 |
||
com.fasterxml.jackson.core:jackson-databind:2.9.8 |
As described in Versioning policy, the minor version number of a Bio-Formats release will always be increased if the version of a non-OME/external dependency is bumped.
Dependency lists for any component can be generated by checking out the code as described in Source code and then running:
cd components/$COMPONENT_NAME
mvn dependency:tree
Examples of usage¶
File reading and performance:¶
MultiFileExample - Simple example of how to open multiple files simultaneously.
ParallelRead - Reads all files in given directory in parallel, using a separate thread for each.
ReadWriteInMemory - Tests the Bio-Formats I/O logic to and from byte arrays in memory.
OrthogonalReader - Reads image data in XZ and YZ order.
File writing:¶
MinimumWriter - A command line utility demonstrating the minimum amount of metadata needed to write a file.
FileExport - Write a file in any supported output format.
TiledExport - Shows how to convert a file one tile at a time, instead of one plane at a time (needed for very large images).
FileExportSPW - Write a file with plate (OME SPW) metadata.
File compression:¶
makeLZW - Converts the given image file to an LZW-compressed TIFF.
Metadata extract/print:¶
GetPhysicalMetadata - Uses Bio-Formats to extract some basic standardized (format-independent) metadata.
ReadPhysicalSize - Reads physical size information uses the units API to display in micrometers.
ImageInfo - A more involved command line utility for thoroughly reading an input file, printing some information about it, and displaying the pixels onscreen using the Bio-Formats viewer.
PrintTimestamps - A command line example demonstrating how to extract timestamps from a file.
PrintLensNA - Uses Bio-Formats to extract lens numerical aperture in a format-independent manner from a dataset.
PrintROIs - A simple example of how to retrieve ROI data parsed from a file.
SubResolutionExample - Demonstration of the sub-resolution API.
Metadata add/edit:¶
EditImageName - Edits the given file’s image name (but does not save back to disk).
EditTiffComment - Allows raw user TIFF comment editing for the given TIFF files.
writeMapAnnotations - Example method to write MapAnnotations to the ome-xml.
CommentSurgery - Edits a TIFF ImageDescription comment, particularly the OME-XML comment found in OME-TIFF files.
Image converters:¶
ImageConverter - A simple command line tool for converting between formats.
FileConvert - Converts a file in any supported format to any supported output format.
ConvertToOmeTiff - Converts the given files to OME-TIFF format.
WritePreCompressedPlanes - Writes the pixels from a set of JPEG files to a single TIFF. The pixel data is used as-is, so no decompression or re-compression is performed.
GeneratePyramidResolutions - Convert a file containing a single large image to a pyramid OME-TIFF.
TiledReaderWriter - Convert a file to OME-TIFF one tile at a time.
OverlappedTiledWriter - Convert a file to OME-TIFF one tile at a time, when the image size is not a multiple of the tile size.
SimpleTiledWriter - Convert a file to OME-TIFF using automatic tiling.
ImageJ plugins:¶
Simple_Read - A simple ImageJ plugin demonstrating how to use Bio-Formats to read files into ImageJ (see ImageJ overview).
Read_Image - An ImageJ plugin that uses Bio-Formats to build up an image stack, reading image planes one by one (see ImageJ overview).
Mass_Importer - A simple plugin for ImageJ that demonstrates how to open all image files in a directory using Bio-Formats, grouping files with similar names to avoiding opening the same dataset more than once (see ImageJ overview).
Image processing utilities:¶
SewTiffs - Stitches the first plane from a collection of TIFFs into a single file.
SumPlanes - Sums together the image planes from the given file,and saves the result to a 16-bit TIFF.
A Note on Java Web Start (bioformats_package.jar vs. formats-gpl.jar)¶
To use Bio-Formats with your Java Web Start application, we recommend using formats-gpl.jar rather than bioformats_package.jar—the latter is merely a bundle of formats-gpl.jar plus all its optional dependencies.
The bioformats_package.jar bundle is intended as a convenience (e.g. to simplify installation as an ImageJ plugin), but is by no means the only solution for developers. We recommend using formats-gpl.jar as a separate entity depending on your needs as a developer.
The bundle is quite large because we have added support for several formats that need large helper libraries (e.g. Imaris’ HDF-based format). However, these additional libraries are optional; Bio-Formats has been coded using reflection so that it can both compile and run without them.
When deploying a JNLP-based application, using bioformats_package.jar directly is not the best approach, since every time Bio-Formats is updated, the server would need to feed another 15+ MB JAR file to the client. Rather, Web Start is a case where you should keep the JARs separate, since JNLP was designed to make management of JAR dependencies trivial for the end user. By keeping formats-gpl.jar and the optional dependencies separate, only a <1 MB JAR needs to be updated when formats-gpl.jar changes.
As a developer, you have the option of packaging formats-gpl.jar with as many or as few optional libraries as you wish, to cut down on file size as needed. You are free to make whatever kind of “stripped down” version you require. You could even build a custom formats-gpl.jar that excludes certain classes, if you like.