use of loci.formats.out.OMETiffWriter in project bioformats by openmicroscopy.
the class OMETiffWriterBigTiffLargeImageWidthTest method testImageWidthWrittenCorrectly.
@Test
public void testImageWidthWrittenCorrectly() throws Exception {
OMETiffWriter writer = new OMETiffWriter();
writer.setBigTiff(true);
writer.setMetadataRetrieve(ms);
writer.setId(target.getAbsolutePath());
writer.saveBytes(0, buf, 0, 0, buf.length, 1);
writer.close();
TiffReader reader = new TiffReader();
reader.setId(target.getAbsolutePath());
assertEquals(SIZE_X, reader.getSizeX());
assertEquals(SIZE_Y, reader.getSizeY());
}
use of loci.formats.out.OMETiffWriter in project bioformats by openmicroscopy.
the class OMETiffWriterUnicodeTest method testImageWidthWrittenCorrectly.
@Test
public void testImageWidthWrittenCorrectly() throws Exception {
OMETiffWriter writer = new OMETiffWriter();
writer.setMetadataRetrieve(ms);
writer.setId(target.getAbsolutePath());
writer.saveBytes(0, buf, 0, 0, buf.length, 1);
writer.close();
ImageReader reader = new ImageReader();
reader.setId(target.getAbsolutePath());
assertEquals(reader.getFormat(), "OME-TIFF");
reader.close();
}
use of loci.formats.out.OMETiffWriter in project bioformats by openmicroscopy.
the class ConvertToOmeTiff method main.
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("Usage: java ConvertToOmeTiff file1 file2 ...");
return;
}
ImageReader reader = new ImageReader();
OMETiffWriter writer = new OMETiffWriter();
for (int i = 0; i < args.length; i++) {
String id = args[i];
int dot = id.lastIndexOf(".");
String outId = (dot >= 0 ? id.substring(0, dot) : id) + ".ome.tif";
System.out.print("Converting " + id + " to " + outId + " ");
// record metadata to OME-XML format
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata omexmlMeta = service.createOMEXMLMetadata();
reader.setMetadataStore(omexmlMeta);
reader.setId(id);
// configure OME-TIFF writer
writer.setMetadataRetrieve(omexmlMeta);
writer.setId(outId);
// writer.setCompression("J2K");
// write out image planes
int seriesCount = reader.getSeriesCount();
for (int s = 0; s < seriesCount; s++) {
reader.setSeries(s);
writer.setSeries(s);
int planeCount = reader.getImageCount();
for (int p = 0; p < planeCount; p++) {
byte[] plane = reader.openBytes(p);
// write plane to output file
writer.saveBytes(p, plane);
System.out.print(".");
}
}
writer.close();
reader.close();
System.out.println(" [done]");
}
}
use of loci.formats.out.OMETiffWriter in project bioformats by openmicroscopy.
the class MakeTestOmeTiff method createWriter.
private OMETiffWriter createWriter(final String name, final CoreMetadata info, final String id) throws FormatException, IOException {
final OMETiffWriter out = new OMETiffWriter();
try {
out.setMetadataRetrieve(createMetadata(name, info));
} catch (final DependencyException e) {
throw new FormatException(e);
} catch (final ServiceException e) {
throw new FormatException(e);
} catch (final EnumerationException e) {
throw new FormatException(e);
}
ensureNonExisting(id);
out.setId(id);
return out;
}
use of loci.formats.out.OMETiffWriter in project bioformats by openmicroscopy.
the class TiledReaderWriter 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);
}
Aggregations