use of loci.formats.ImageReader 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.ImageReader in project bioformats by openmicroscopy.
the class MakeLZW method main.
public static void main(String[] args) throws Exception {
ImageReader reader = new ImageReader();
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata omexmlMeta = service.createOMEXMLMetadata();
reader.setMetadataStore(omexmlMeta);
TiffWriter writer = new TiffWriter();
for (int i = 0; i < args.length; i++) {
String inFile = args[i];
String outFile = "lzw-" + inFile;
System.out.print("Converting " + inFile + " to " + outFile);
reader.setId(inFile);
writer.setMetadataRetrieve(omexmlMeta);
writer.setCompression("LZW");
writer.setId(outFile);
int planeCount = reader.getImageCount();
for (int p = 0; p < planeCount; p++) {
System.out.print(".");
byte[] plane = reader.openBytes(p);
writer.saveBytes(p, plane);
}
System.out.println(" [done]");
}
}
use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class MultiFileExportExample method main.
public static void main(String[] args) throws FormatException, IOException {
if (args.length < 2) {
System.out.println("Usage: java MultiFileExportExample <infile> <output file extension>");
System.exit(1);
}
ImageReader reader = new ImageReader();
IMetadata metadata;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
metadata = service.createOMEXMLMetadata();
} catch (DependencyException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
} catch (ServiceException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
}
reader.setMetadataStore(metadata);
reader.setId(args[0]);
ImageWriter writer = new ImageWriter();
writer.setMetadataRetrieve(metadata);
String baseFile = args[0].substring(0, args[0].lastIndexOf("."));
writer.setId(baseFile + "_s0_z0" + args[1]);
for (int series = 0; series < reader.getSeriesCount(); series++) {
reader.setSeries(series);
writer.setSeries(series);
int planesPerFile = reader.getImageCount() / reader.getSizeZ();
for (int z = 0; z < reader.getSizeZ(); z++) {
String file = baseFile + "_s" + series + "_z" + z + args[1];
writer.changeOutputFile(file);
for (int image = 0; image < planesPerFile; image++) {
int[] zct = FormatTools.getZCTCoords(reader.getDimensionOrder(), 1, reader.getEffectiveSizeC(), reader.getSizeT(), planesPerFile, image);
int index = FormatTools.getIndex(reader, z, zct[1], zct[2]);
writer.saveBytes(image, reader.openBytes(index));
}
}
}
reader.close();
writer.close();
}
use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class PrintLensNA method main.
public static void main(String[] args) throws DependencyException, FormatException, IOException, ServiceException {
// parse command line arguments
if (args.length < 1) {
System.err.println("Usage: java PrintLensNA imageFile");
System.exit(1);
}
String id = args[0];
// configure reader
IFormatReader reader = new ImageReader();
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata meta = service.createOMEXMLMetadata();
reader.setMetadataStore(meta);
System.out.println("Initializing file: " + id);
// parse metadata
reader.setId(id);
// output metadata values
int instrumentCount = meta.getInstrumentCount();
System.out.println("There are " + instrumentCount + " instrument(s) associated with this file");
for (int i = 0; i < instrumentCount; i++) {
int objectiveCount = meta.getObjectiveCount(i);
System.out.println();
System.out.println("Instrument #" + i + " [" + meta.getInstrumentID(i) + "]: " + objectiveCount + " objective(s) found");
for (int o = 0; o < objectiveCount; o++) {
Double lensNA = meta.getObjectiveLensNA(i, o);
System.out.println("\tObjective #" + o + " [" + meta.getObjectiveID(i, o) + "]: LensNA=" + lensNA);
}
}
}
use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class PrintTimestamps method main.
public static void main(String[] args) throws Exception {
// parse command line arguments
if (args.length < 1) {
System.err.println("Usage: java PrintTimestamps imageFile [seriesNo]");
System.exit(1);
}
String id = args[0];
int series = args.length > 1 ? Integer.parseInt(args[1]) : 0;
// enable debugging
// FormatReader.debug = true;
// create OME-XML metadata store of the latest schema version
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata meta = service.createOMEXMLMetadata();
// or if you want a specific schema version, you can use:
// IMetadata meta = service.createOMEXMLMetadata(null, "2009-02");
// meta.createRoot();
// create format reader
IFormatReader reader = new ImageReader();
reader.setMetadataStore(meta);
// initialize file
System.out.println("Initializing " + id);
reader.setId(id);
int seriesCount = reader.getSeriesCount();
if (series < seriesCount)
reader.setSeries(series);
series = reader.getSeries();
System.out.println("\tImage series = " + series + " of " + seriesCount);
printDimensions(reader);
printGlobalTiming(meta, series);
printTimingPerTimepoint(meta, series);
printTimingPerPlane(meta, series);
}
Aggregations