Search in sources :

Example 41 with IMetadata

use of loci.formats.meta.IMetadata 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]");
    }
}
Also used : IMetadata(loci.formats.meta.IMetadata) TiffWriter(loci.formats.out.TiffWriter) ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) OMEXMLService(loci.formats.services.OMEXMLService)

Example 42 with IMetadata

use of loci.formats.meta.IMetadata 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();
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) ImageWriter(loci.formats.ImageWriter) ImageReader(loci.formats.ImageReader) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException)

Example 43 with IMetadata

use of loci.formats.meta.IMetadata 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);
        }
    }
}
Also used : IFormatReader(loci.formats.IFormatReader) IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) OMEXMLService(loci.formats.services.OMEXMLService)

Example 44 with IMetadata

use of loci.formats.meta.IMetadata 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);
}
Also used : IMetadata(loci.formats.meta.IMetadata) IFormatReader(loci.formats.IFormatReader) ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) OMEXMLService(loci.formats.services.OMEXMLService)

Example 45 with IMetadata

use of loci.formats.meta.IMetadata 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]");
    }
}
Also used : OMETiffWriter(loci.formats.out.OMETiffWriter) IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) OMEXMLService(loci.formats.services.OMEXMLService)

Aggregations

IMetadata (loci.formats.meta.IMetadata)62 ServiceFactory (loci.common.services.ServiceFactory)35 OMEXMLService (loci.formats.services.OMEXMLService)35 FormatException (loci.formats.FormatException)19 ImageReader (loci.formats.ImageReader)19 ServiceException (loci.common.services.ServiceException)17 Test (org.testng.annotations.Test)17 DependencyException (loci.common.services.DependencyException)15 SkipException (org.testng.SkipException)15 Length (ome.units.quantity.Length)13 IOException (java.io.IOException)9 ImageWriter (loci.formats.ImageWriter)6 Time (ome.units.quantity.Time)6 PositiveInteger (ome.xml.model.primitives.PositiveInteger)6 File (java.io.File)5 IFormatReader (loci.formats.IFormatReader)5 IFormatWriter (loci.formats.IFormatWriter)5 OMETiffWriter (loci.formats.out.OMETiffWriter)5 TiffWriter (loci.formats.out.TiffWriter)5 EnumerationException (ome.xml.model.enums.EnumerationException)4