[ome-users] Read write large tiff
Erwan Bocher
erwan.bocher at ec-nantes.fr
Tue May 29 12:30:34 BST 2012
Dear,
I want to read, process and write a big tiff with the bioformats lib. I
use the code proposed on the official wiki that permits to read data
block by block. The code runs without any errors but the result image
is wrong. Pixel values are shifted and the total size of the image is
huge (original image 93 mo : result image more than 600 mo).
Thanks for any advice you could give!
Greetings.
// create a reader that will automatically handle any
supported format
IFormatReader reader = new ImageReader();
// tell the reader where to store the metadata from the
dataset
reader.setMetadataStore(MetadataTools.createOMEXMLMetadata());
// initialize the dataset
reader.setId(path);
// create a writer that will automatically handle any
supported output format
IFormatWriter writer = new ImageWriter();
// give the writer a MetadataRetrieve object, which
encapsulates all of the
// dimension information for the dataset (among many
other things)
writer.setMetadataRetrieve(MetadataTools.asRetrieve(reader.getMetadataStore()));
// initialize the writer
writer.setId("/tmp/test.tif");
int tileWidth = 1024;
int tileHeight = 1024;
System.out.println("Series " + reader.getSeriesCount());
for (int series = 0; series < reader.getSeriesCount();
series++) {
reader.setSeries(series);
writer.setSeries(series);
// determine how many tiles are in each image
plane
// for simplicity, we'll assume that the image
width and height are multiples of 1024
int tileRows = reader.getSizeY() / tileHeight;
int tileColumns = reader.getSizeX() / tileWidth;
for (int image = 0; image <
reader.getImageCount(); image++) {
for (int row = 0; row <
tileRows; row++) {
for (int col = 0; col <
tileColumns; col++) {
// open a tile - in
addition to the image index, we need to specify
// the (x, y)
coordinate of the upper left corner of the tile, along with the
// width and height of
the tile
byte[] tile =
reader.openBytes(image, col * tileWidth, row * tileHeight, tileWidth,
tileHeight);
writer.saveBytes(image,
tile, col * tileWidth, row * tileHeight, tileWidth, tileHeight);
}
}
}
}
reader.close();
writer.close();
More information about the ome-users
mailing list