Search in sources :

Example 1 with IMetadata

use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.

the class ImagePlusReader method readPlanes.

private ImageStack readPlanes(ImportProcess process, int s, List<LUT> luts, boolean thumbnail) throws FormatException, IOException {
    final ImageProcessorReader reader = process.getReader();
    reader.setSeries(s);
    final int zCount = process.getZCount(s);
    final int cCount = process.getCCount(s);
    final int tCount = process.getTCount(s);
    final IMetadata meta = process.getOMEMetadata();
    // get list of planes to load
    final boolean[] load = getPlanesToLoad(s);
    int current = 0, total = 0;
    for (int j = 0; j < load.length; j++) if (load[j])
        total++;
    final List<ImageProcessor> procs = new ArrayList<ImageProcessor>();
    final List<String> labels = new ArrayList<String>();
    // read applicable image planes
    final Region region = process.getCropRegion(s);
    for (int i = 0; i < load.length; i++) {
        if (!load[i])
            continue;
        // limit message update rate
        updateTiming(s, current, current++, total);
        // get image processor for ith plane
        final ImageProcessor[] p = readProcessors(process, i, region, thumbnail);
        if (p == null || p.length == 0) {
            throw new FormatException("Cannot read plane #" + i);
        }
        // generate a label for ith plane
        String label = constructSliceLabel(i, reader, meta, s, zCount, cCount, tCount);
        for (ImageProcessor ip : p) {
            procs.add(ip);
            labels.add(label);
        }
    }
    return createStack(procs, labels, luts);
}
Also used : ImageProcessor(ij.process.ImageProcessor) IMetadata(loci.formats.meta.IMetadata) ImageProcessorReader(loci.plugins.util.ImageProcessorReader) ArrayList(java.util.ArrayList) Region(loci.common.Region) FormatException(loci.formats.FormatException)

Example 2 with IMetadata

use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.

the class ImagePlusReader method createVirtualStack.

private ImageStack createVirtualStack(ImportProcess process, int s, List<LUT> luts) throws FormatException, IOException {
    final ImporterOptions options = process.getOptions();
    final ImageProcessorReader reader = process.getReader();
    reader.setSeries(s);
    final int zCount = process.getZCount(s);
    final int cCount = process.getCCount(s);
    final int tCount = process.getTCount(s);
    final IMetadata meta = process.getOMEMetadata();
    final int imageCount = reader.getImageCount();
    // CTR FIXME: Make virtual stack work with different color modes?
    final BFVirtualStack virtualStack = new BFVirtualStack(options.getId(), reader, false, false, false);
    for (int i = 0; i < imageCount; i++) {
        String label = constructSliceLabel(i, reader, meta, s, zCount, cCount, tCount);
        virtualStack.addSlice(label);
    }
    if (luts != null) {
        for (int c = 0; c < cCount; c++) {
            int index = reader.getIndex(0, c, 0);
            ImageProcessor ip = reader.openProcessors(index)[0];
            final ColorModel cm = ip.getColorModel();
            final LUT lut = cm instanceof LUT ? (LUT) cm : null;
            luts.add(lut);
        }
    }
    return virtualStack;
}
Also used : ImageProcessor(ij.process.ImageProcessor) IMetadata(loci.formats.meta.IMetadata) ImageProcessorReader(loci.plugins.util.ImageProcessorReader) ColorModel(java.awt.image.ColorModel) LUT(ij.process.LUT) BFVirtualStack(loci.plugins.util.BFVirtualStack)

Example 3 with IMetadata

use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.

the class ImageViewer method open.

/**
 * Opens the given data source using the current format reader.
 */
public void open(String id) {
    wait(true);
    try {
        // Location f = new Location(id);
        // id = f.getAbsolutePath();
        IMetadata meta = null;
        if (omexmlService != null) {
            try {
                meta = omexmlService.createOMEXMLMetadata();
                myReader.setMetadataStore(meta);
            } catch (ServiceException exc) {
                LOGGER.debug("Could not create OME-XML metadata", exc);
            }
        }
        if (meta == null) {
            LOGGER.info("OME metadata unavailable");
        }
        myReader.setId(id);
        int num = myReader.getImageCount();
        ProgressMonitor progress = new ProgressMonitor(this, "Reading " + id, null, 0, num + 1);
        sizeZ = myReader.getSizeZ();
        sizeT = myReader.getSizeT();
        sizeC = myReader.getEffectiveSizeC();
        // if (myReader.isRGB(id)) sizeC = (sizeC + 2) / 3; // adjust for RGB
        progress.setProgress(1);
        BufferedImage[] img = new BufferedImage[num];
        for (int i = 0; i < num; i++) {
            if (progress.isCanceled())
                break;
            img[i] = myReader.openImage(i);
            if (i == 0)
                setImages(myReader, img);
            progress.setProgress(i + 2);
        }
        myReader.close(true);
    } catch (FormatException exc) {
        LOGGER.info("", exc);
        wait(false);
        return;
    } catch (IOException exc) {
        LOGGER.info("", exc);
        wait(false);
        return;
    }
    wait(false);
}
Also used : ProgressMonitor(javax.swing.ProgressMonitor) IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) FormatException(loci.formats.FormatException)

Example 4 with IMetadata

use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.

the class GetPhysicalMetadata method main.

public static void main(String[] args) throws Exception {
    // parse command line arguments
    if (args.length < 1) {
        System.err.println("Usage: java GetMetadata imageFile [seriesNo]");
        System.exit(1);
    }
    String id = args[0];
    int series = args.length > 1 ? Integer.parseInt(args[1]) : 0;
    // create OME-XML metadata store
    ServiceFactory factory = new ServiceFactory();
    OMEXMLService service = factory.getInstance(OMEXMLService.class);
    IMetadata meta = service.createOMEXMLMetadata();
    // 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);
    printPixelDimensions(reader);
    printPhysicalDimensions(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 5 with IMetadata

use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.

the class MinimumWriter method main.

public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.out.println("Please specify an output file name.");
        System.exit(1);
    }
    String id = args[0];
    // create blank 512x512 image
    System.out.println("Creating random image...");
    int w = 512, h = 512, c = 1;
    int pixelType = FormatTools.UINT16;
    byte[] img = new byte[w * h * c * FormatTools.getBytesPerPixel(pixelType)];
    // fill with random data
    for (int i = 0; i < img.length; i++) img[i] = (byte) (256 * Math.random());
    // create metadata object with minimum required metadata fields
    System.out.println("Populating metadata...");
    ServiceFactory factory = new ServiceFactory();
    OMEXMLService service = factory.getInstance(OMEXMLService.class);
    IMetadata meta = service.createOMEXMLMetadata();
    MetadataTools.populateMetadata(meta, 0, null, false, "XYZCT", FormatTools.getPixelTypeString(pixelType), w, h, 1, c, 1, c);
    // write image plane to disk
    System.out.println("Writing image to '" + id + "'...");
    IFormatWriter writer = new ImageWriter();
    writer.setMetadataRetrieve(meta);
    writer.setId(id);
    writer.saveBytes(0, img);
    writer.close();
    System.out.println("Done.");
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) 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