use of loci.formats.out.OMETiffWriter in project bioformats by openmicroscopy.
the class OMETiffWriterTest method testCompanion.
@Test
public void testCompanion() throws Exception {
Path wd = Files.createTempDirectory(this.getClass().getName());
File outFile = wd.resolve("test.ome.tif").toFile();
File cFile = wd.resolve("test.companion.ome").toFile();
String companion = cFile.getAbsolutePath();
DynamicMetadataOptions options = new DynamicMetadataOptions();
options.set(OMETiffWriter.COMPANION_KEY, companion);
int planeCount = WriterUtilities.SIZE_Z * WriterUtilities.SIZE_C * WriterUtilities.SIZE_T;
OMETiffWriter cwriter = new OMETiffWriter();
cwriter.setMetadataOptions(options);
cwriter.setMetadataRetrieve(metadata);
cwriter.setId(outFile.getAbsolutePath());
cwriter.setSeries(0);
byte[] img = new byte[WriterUtilities.SIZE_X * WriterUtilities.SIZE_Y];
for (int i = 0; i < planeCount; i++) {
cwriter.saveBytes(i, img);
}
cwriter.close();
assertTrue(cFile.exists());
OMETiffReader reader = new OMETiffReader();
reader.setId(companion);
assertEquals(reader.getSizeX(), WriterUtilities.SIZE_X);
assertEquals(reader.getSizeY(), WriterUtilities.SIZE_Y);
assertEquals(reader.getSizeZ(), WriterUtilities.SIZE_Z);
assertEquals(reader.getSizeC(), WriterUtilities.SIZE_C);
assertEquals(reader.getSizeT(), WriterUtilities.SIZE_T);
reader.close();
outFile.deleteOnExit();
cFile.deleteOnExit();
wd.toFile().deleteOnExit();
}
use of loci.formats.out.OMETiffWriter in project bioformats by openmicroscopy.
the class OverlappedTiledWriter method initialize.
/**
* Set up the file reader and writer, ensuring that the input file is
* associated with the reader and the output file is associated with the
* writer.
*
* @return true if the reader and writer were successfully set up, or false
* if an error occurred
* @throws DependencyException thrown if failed to create an OMEXMLService
* @throws IOException thrown if unable to setup input or output stream for reader or writer
* @throws FormatException thrown if invalid ID set for reader or writer or invalid tile size set
* @throws ServiceException thrown if unable to create OME-XML meta data
*/
private void initialize() throws DependencyException, FormatException, IOException, ServiceException {
// construct the object that stores OME-XML metadata
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata omexml = service.createOMEXMLMetadata();
// set up the reader and associate it with the input file
reader = new ImageReader();
reader.setMetadataStore(omexml);
reader.setId(inputFile);
// set up 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);
}
use of loci.formats.out.OMETiffWriter in project bioformats by openmicroscopy.
the class OrthogonalReader method initialiseWriter.
private OMETiffWriter initialiseWriter(String fileName, ImageReader reader) throws Exception {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata metadata = service.createOMEXMLMetadata();
MetadataRetrieve mr = (MetadataRetrieve) reader.getMetadataStore();
Length originalSizeX = mr.getPixelsPhysicalSizeX(0);
Length originalSizeY = mr.getPixelsPhysicalSizeY(0);
Length originalSizeZ = mr.getPixelsPhysicalSizeZ(0);
// Original XY planes
// XZ planes
MetadataTools.populateMetadata(metadata, 0, "XZ", reader.isLittleEndian(), reader.getDimensionOrder(), FormatTools.getPixelTypeString(reader.getPixelType()), reader.getSizeX(), reader.getSizeZ(), reader.getSizeY(), 1, 1, 1);
metadata.setPixelsPhysicalSizeX(originalSizeX, 0);
metadata.setPixelsPhysicalSizeY(originalSizeZ, 0);
metadata.setPixelsPhysicalSizeZ(originalSizeY, 0);
// YZ planes
MetadataTools.populateMetadata(metadata, 1, "YZ", reader.isLittleEndian(), reader.getDimensionOrder(), FormatTools.getPixelTypeString(reader.getPixelType()), reader.getSizeY(), reader.getSizeZ(), reader.getSizeX(), 1, 1, 1);
metadata.setPixelsPhysicalSizeX(originalSizeY, 1);
metadata.setPixelsPhysicalSizeY(originalSizeZ, 1);
metadata.setPixelsPhysicalSizeZ(originalSizeX, 1);
OMETiffWriter writer = new OMETiffWriter();
writer.setMetadataRetrieve(metadata);
writer.setId(fileName);
return writer;
}
use of loci.formats.out.OMETiffWriter in project bioformats by openmicroscopy.
the class SimpleTiledWriter method initialize.
/**
* Set up the file reader and writer, ensuring that the input file is
* associated with the reader and the output file is associated with the
* writer.
*
* @return true if the reader and writer were successfully set up, or false
* if an error occurred
* @throws DependencyException thrown if failed to create an OMEXMLService
* @throws IOException thrown if unable to setup input or output stream for reader or writer
* @throws FormatException thrown if invalid ID set for reader or writer or invalid tile size set
* @throws ServiceException thrown if unable to create OME-XML meta data
*/
private void initialize() throws DependencyException, FormatException, IOException, ServiceException {
// construct the object that stores OME-XML metadata
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata omexml = service.createOMEXMLMetadata();
// set up the reader and associate it with the input file
reader = new ImageReader();
reader.setMetadataStore(omexml);
reader.setId(inputFile);
/* initialize-tiling-writer-example-start */
// set up 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);
/* initialize-tiling-writer-example-end */
}
use of loci.formats.out.OMETiffWriter in project bioformats by openmicroscopy.
the class OMETiffWriterTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
writer = new OMETiffWriter();
metadata = WriterUtilities.createMetadata();
for (int i = 0; i < 1024 * 1024; i++) {
buf[i] = (byte) (i % 255);
}
}
Aggregations