Search in sources :

Example 46 with ImageReader

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();
}
Also used : OMETiffWriter(loci.formats.out.OMETiffWriter) ImageReader(loci.formats.ImageReader) Test(org.testng.annotations.Test)

Example 47 with ImageReader

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]");
    }
}
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 48 with ImageReader

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();
}
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 49 with ImageReader

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);
        }
    }
}
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 50 with ImageReader

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);
}
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)

Aggregations

ImageReader (loci.formats.ImageReader)71 ServiceFactory (loci.common.services.ServiceFactory)23 OMEXMLService (loci.formats.services.OMEXMLService)23 FormatException (loci.formats.FormatException)20 IFormatReader (loci.formats.IFormatReader)20 IMetadata (loci.formats.meta.IMetadata)19 Test (org.testng.annotations.Test)15 IOException (java.io.IOException)11 ChannelFiller (loci.formats.ChannelFiller)11 DependencyException (loci.common.services.DependencyException)10 ServiceException (loci.common.services.ServiceException)10 ChannelSeparator (loci.formats.ChannelSeparator)10 MinMaxCalculator (loci.formats.MinMaxCalculator)10 BufferedImageReader (loci.formats.gui.BufferedImageReader)8 ImageWriter (loci.formats.ImageWriter)7 File (java.io.File)6 FileStitcher (loci.formats.FileStitcher)6 OMETiffWriter (loci.formats.out.OMETiffWriter)6 Location (loci.common.Location)5 DimensionSwapper (loci.formats.DimensionSwapper)5