Java:
ImageReader reader = new ImageReader();
IMetadata omeMetadata = MetadataTools.createOMEXMLMetadata();
reader.setMetadataStore(omeMetadata);
reader.setId("/PATH/TO/FILE");
for (int plane = 0; plane < reader.getImageCount(); plane++) {
byte[] image = reader.openBytes(plane);
Number timestamp = omeMetadata.getPlaneDeltaT(0, plane).value();
}
ImageJ macro:
run("Bio-Formats Macro Extensions");
Ext.setId("/PATH/TO/FILE");
Ext.getImageCount(imageCount);
timestamps = newArray(imageCount);
for (plane=0; plane < imageCount; plane++) {
Ext.openImage("image #" + plane, plane);
Ext.getPlaneTimingDeltaT(timestamps[plane], plane);
}
MATLAB:
r = bfGetReader("/PATH/TO/FILE");
imageCount = r.getImageCount();
omeMetadata = r.getMetadataStore();
for plane = 1:imageCount
image = bfGetPlane(r, plane, varargin{:});
timestamp = omeMetadata.getPlaneDeltaT(0, plane - 1).value().doubleValue();
end
Python:
reader = bioformats.get_image_reader(None, path="/PATH/TO/FILE")
imageCount = reader.rdr.getImageCount()
omeMetadata = javabridge.JWrapper(reader.rdr.getMetadataStore())
for plane in range(0, imageCount):
image = reader.read(series=0, index=plane, rescale=False)
timestamp = omeMetadata.getPlaneDeltaT(0, plane)
R:
reader = .jnew("loci.formats.ImageReader")
.jcall(reader, , "setId", file)
omeMetadata = .jcall(reader, "", "getMetadataStore")
image = .jcall(reader, "[B", "openBytes", 0)
timestamp = .jcall(omeMetadata, "", "getPlaneDeltaT", 0, 0)
See the Bio-Formats version history
See the Bio-Formats schema history
public int setTileSizeX(int tileSize) throws FormatException
public int setTileSizeY(int tileSize) throws FormatException
public int getTileSizeX() throws FormatException
public int getTileSizeY() throws FormatException
See full example at SimpleTiledWriter
Simple Tiled Writer
// construct the object that stores OME-XML metadata
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata omexml = service.createOMEXMLMetadata();
// setup the reader and associate it with the input file
reader = new ImageReader();
reader.setMetadataStore(omexml);
reader.setId(inputFile);
// setup the writer and associate it with the output file
writer = new OMETiffWriter();
writer.setMetadataRetrieve(omexml);
writer.setInterleaved(reader.isInterleaved());
// set the tile size height and width for writing
this.tileSizeX = writer.setTileSizeX(tileSizeX);
this.tileSizeY = writer.setTileSizeY(tileSizeY);
writer.setId(outputFile);
byte[] buf = new byte[FormatTools.getPlaneSize(reader)];
for (int series=0; series < reader.getSeriesCount(); series++) {
reader.setSeries(series);
writer.setSeries(series);
// convert each image in the current series
for (int image=0; image < reader.getImageCount(); image++) {
// Read tiles from the input file and write them to the output OME-Tiff
// The OME-Tiff Writer will automatically write the images in a tiled format
buf = reader.openBytes(image);
writer.saveBytes(image, buf);
}
}
See full example at TiledReaderWriter
Tiled Reader Writer
int bpp = FormatTools.getBytesPerPixel(reader.getPixelType());
int tilePlaneSize = tileSizeX * tileSizeY * reader.getRGBChannelCount() * bpp;
byte[] buf = new byte[tilePlaneSize];
for (int series=0; series < reader.getSeriesCount(); series++) {
reader.setSeries(series);
writer.setSeries(series);
// convert each image in the current series
for (int image=0; image < reader.getImageCount(); image++) {
int width = reader.getSizeX();
int height = reader.getSizeY();
// Determined the number of tiles to read and write
int nXTiles = width / tileSizeX;
int nYTiles = height / tileSizeY;
if (nXTiles * tileSizeX != width) nXTiles++;
if (nYTiles * tileSizeY != height) nYTiles++;
for (int y=0; y < nYTiles; y++) {
for (int x=0; x < nXTiles; x++) {
// The x and y coordinates for the current tile
int tileX = x * tileSizeX;
int tileY = y * tileSizeY;
// Read tiles from the input file and write them to the output OME-Tiff
buf = reader.openBytes(image, tileX, tileY, tileSizeX, tileSizeY);
writer.saveBytes(image, buf, tileX, tileY, tileSizeX, tileSizeY);
}
}
}
}
See full list of Reader and Writer options
Retrieving Options
MetadataOptions options = writer.getMetadataOptions();
if (options instanceof DynamicMetadataOptions) {
boolean value = ((DynamicMetadataOptions) options).getBoolean("ometiff.companion");
}
Setting Options
MetadataOptions options = reader.getMetadataOptions();
if (options instanceof DynamicMetadataOptions) {
((DynamicMetadataOptions) options).setBoolean("nativend2.chunkmap", true);
reader.setMetadataOptions(options);
}
showinf example
showinf -option nativend2.chunkmap true inputFile.nd2
bfconvert example
bfconvert -option ometiff.companionoutputFile.companion.ome inputFile.tiff outputFile.ome.tiff