Skip to content

Latest commit

 

History

History
310 lines (259 loc) · 17.8 KB

reader-guide.rst

File metadata and controls

310 lines (259 loc) · 17.8 KB

Writing a new file format reader

This document is a brief guide to writing new Bio-Formats file format readers.

All format readers should extend either :javadoc:`loci.formats.FormatReader <loci/formats/FormatReader.html>` or :javadoc:`an existing reader <loci/formats/in/package-summary.html>`.

Methods to override

Note that if the new format is a variant of a format currently supported by Bio-Formats, it is more efficient to make the new reader a subclass of the existing reader (rather than subclassing :javadoc:`loci.formats.FormatReader <loci/formats/FormatReader.html>`). In this case, it is usually sufficient to override :javadoc:`initFile(java.lang.String) <loci/formats/FormatReader.html#initFile-java.lang.String->` and :javadoc:`isThisType(byte[]) <loci/formats/FormatReader.html#isThisType-byte:A->`.

Every reader also has an instance of :javadoc:`loci.formats.CoreMetadata <loci/formats/CoreMetadata.html>`. All readers should populate the fields in CoreMetadata, which are essential to reading image planes.

If you read from a file using something other than :common_javadoc:`loci.common.RandomAccessInputStream <loci/common/RandomAccessInputStream.html>` or :common_javadoc:`loci.common.Location <loci/common/Location.html>`, you must use the file name returned by Location.getMappedId(String), not the file name passed to the reader. Thus, a stub for initFile(String) might look like this:

protected void initFile(String id) throws FormatException, IOException {
  super.initFile(id);

  RandomAccessInputStream in = new RandomAccessInputStream(id);
  // alternatively,
  //FileInputStream in = new FileInputStream(Location.getMappedId(id));

  // read basic file structure and metadata from stream
}

For more details, see :common_javadoc:`loci.common.Location.mapId(java.lang.String, java.lang.String) <loci/common/Location.html#mapId-java.lang.String-java.lang.String->` and :common_javadoc:`loci.common.Location.getMappedId(java.lang.String) <loci/common/Location.html#getMappedId-java.lang.String->`.

Variables to populate

There are a number of global variables defined in :javadoc:`loci.formats.FormatReader <loci/formats/FormatReader.html>` that should be populated in the constructor of any implemented reader.

These variables are:

Other useful things

Argument Action
-version print the library version and exit
file the image file to read
-nopix read metadata only, not pixels
-nocore do not output core metadata
-nometa do not parse format-specific metadata table
-nofilter do not filter metadata fields
-thumbs read thumbnails instead of normal pixels
-minmax compute min/max statistics
-merge combine separate channels into RGB image
-nogroup force multi-file datasets to be read as individual files
-stitch stitch files with similar names
-separate split RGB image into separate channels
-expand expand indexed color to RGB
-omexml populate OME-XML metadata
-normalize normalize floating point images*
-fast paint RGB images as quickly as possible*
-debug turn on debugging output
-range specify range of planes to read (inclusive)
-series specify which image series to read
-swap override the default input dimension order
-shuffle override the default output dimension order
-map specify file on disk to which name should be mapped
-preload pre-read entire file into a buffer; significantly reduces the time required to read the images, but requires more memory
-crop crop images before displaying; argument is 'x,y,w,h'
-autoscale used in combination with '-fast' to automatically adjust brightness and contrast
-novalid do not perform validation of OME-XML
-omexml-only only output the generated OME-XML
-format read file with a particular reader (e.g., ZeissZVI)

* = may result in loss of precision

If you have questions about Bio-Formats, please contact :imagesc:`the forums <tag/bio-formats>`.