Search in sources :

Example 41 with OMEXMLService

use of loci.formats.services.OMEXMLService in project bioformats by openmicroscopy.

the class Schema2011_06_File_Upgrade_Test method setUp.

@BeforeClass
public void setUp() throws Exception {
    InputStream source = this.getClass().getResourceAsStream(ref.FILE_LOCATION);
    byte[] b = new byte[source.available()];
    source.read(b);
    source.close();
    String xml = new String(b);
    ServiceFactory sf = new ServiceFactory();
    OMEXMLService service = sf.getInstance(OMEXMLService.class);
    ome = (OME) service.createOMEXMLRoot(xml);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) InputStream(java.io.InputStream) OMEXMLService(loci.formats.services.OMEXMLService) BeforeClass(org.testng.annotations.BeforeClass)

Example 42 with OMEXMLService

use of loci.formats.services.OMEXMLService in project bioformats by openmicroscopy.

the class OMETiffWriterUnicodeTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    target = File.createTempFile("OMETiffWriterUnicodeTest", ".ome.tiff");
    ServiceFactory sf = new ServiceFactory();
    OMEXMLService service = sf.getInstance(OMEXMLService.class);
    ms = service.createOMEXMLMetadata();
    ms.setImageID("Image:1", 0);
    ms.setPixelsID("Pixels:1", 0);
    ms.setPixelsDimensionOrder(DimensionOrder.XYZCT, 0);
    ms.setPixelsSizeX(new PositiveInteger(SIZE_X), 0);
    ms.setPixelsSizeY(new PositiveInteger(SIZE_Y), 0);
    ms.setPixelsSizeZ(new PositiveInteger(SIZE_Z), 0);
    ms.setPixelsSizeC(new PositiveInteger(SIZE_C), 0);
    ms.setPixelsSizeT(new PositiveInteger(SIZE_T), 0);
    ms.setPixelsPhysicalSizeX(new Length(10, UNITS.MICROMETER), 0);
    ms.setPixelsPhysicalSizeX(new Length(10, UNITS.MICROMETER), 0);
    ms.setPixelsPhysicalSizeX(new Length(10, UNITS.MICROMETER), 0);
    ms.setPixelsType(PixelType.UINT8, 0);
    ms.setPixelsBinDataBigEndian(true, 0, 0);
    ms.setChannelID("Channel:1", 0, 0);
    ms.setChannelSamplesPerPixel(new PositiveInteger(1), 0, 0);
}
Also used : PositiveInteger(ome.xml.model.primitives.PositiveInteger) ServiceFactory(loci.common.services.ServiceFactory) Length(ome.units.quantity.Length) OMEXMLService(loci.formats.services.OMEXMLService) BeforeClass(org.testng.annotations.BeforeClass)

Example 43 with OMEXMLService

use of loci.formats.services.OMEXMLService 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 44 with OMEXMLService

use of loci.formats.services.OMEXMLService 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 45 with OMEXMLService

use of loci.formats.services.OMEXMLService 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)

Aggregations

OMEXMLService (loci.formats.services.OMEXMLService)59 ServiceFactory (loci.common.services.ServiceFactory)57 IMetadata (loci.formats.meta.IMetadata)35 DependencyException (loci.common.services.DependencyException)28 ServiceException (loci.common.services.ServiceException)26 FormatException (loci.formats.FormatException)23 ImageReader (loci.formats.ImageReader)21 PositiveInteger (ome.xml.model.primitives.PositiveInteger)12 IOException (java.io.IOException)11 MetadataStore (loci.formats.meta.MetadataStore)7 File (java.io.File)6 Location (loci.common.Location)6 ImageWriter (loci.formats.ImageWriter)6 OMEXMLMetadata (loci.formats.ome.OMEXMLMetadata)6 Length (ome.units.quantity.Length)6 BeforeClass (org.testng.annotations.BeforeClass)6 IFormatWriter (loci.formats.IFormatWriter)5 MissingLibraryException (loci.formats.MissingLibraryException)5 OMETiffWriter (loci.formats.out.OMETiffWriter)5 ArrayList (java.util.ArrayList)4