[ome-users] Read write large tiff
Melissa Linkert
melissa at glencoesoftware.com
Tue May 29 15:59:28 BST 2012
Hi Erwan,
> 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).
What are the dimensions of the original file (X, Y, and number of
planes)? Is the original image data compressed?
I would guess that the tile dimensions in the code need to be adjusted
(as alluded to on the wiki page), but without knowing the specifics of
the input file it's a little tricky to say for sure.
Regards,
-Melissa
On Tue, May 29, 2012 at 01:30:34PM +0200, Erwan Bocher wrote:
> 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();
> _______________________________________________
> ome-users mailing list
> ome-users at lists.openmicroscopy.org.uk
> http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-users
More information about the ome-users
mailing list