Search in sources :

Example 6 with OMEXMLMetadata

use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.

the class OBFReader method initFile.

@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    currentInflatedFrame.series = -1;
    currentInflatedFrame.number = -1;
    in = new RandomAccessInputStream(id);
    file_version = getFileVersion(in);
    long stackPosition = in.readLong();
    final int lengthOfDescription = in.readInt();
    final String description = in.readString(lengthOfDescription);
    metadata.put("Description", description);
    if (file_version >= 2) {
        final long meta_data_position = in.readLong();
        final long current_position = in.getFilePointer();
        in.seek(meta_data_position);
        for (String key = readString(); key.length() > 0; key = readString()) {
            if (key.equals("ome_xml")) {
                final String ome_xml = readString();
                try {
                    ServiceFactory factory = new ServiceFactory();
                    OMEXMLService service = factory.getInstance(OMEXMLService.class);
                    if (service.validateOMEXML(ome_xml)) {
                        ome_meta_data = service.createOMEXMLMetadata(ome_xml);
                        for (int image = 0; image != ome_meta_data.getImageCount(); ++image) {
                            if (ome_meta_data.getPixelsBigEndian(image) == null) {
                                ome_meta_data.setPixelsBigEndian(Boolean.FALSE, image);
                            }
                            int channels = ome_meta_data.getChannelCount(image);
                            for (int channel = 0; channel != channels; ++channel) {
                                if (ome_meta_data.getChannelSamplesPerPixel(image, channel) == null) {
                                    ome_meta_data.setChannelSamplesPerPixel(new PositiveInteger(1), image, channel);
                                }
                            }
                        }
                        service.convertMetadata(ome_meta_data, metadataStore);
                        OMEXMLMetadata reference = service.getOMEMetadata(service.asRetrieve(metadataStore));
                        for (int image = 0; image != ome_meta_data.getImageCount(); ++image) {
                            service.addMetadataOnly(reference, image);
                        }
                    }
                } catch (DependencyException exception) {
                    throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, exception);
                } catch (ServiceException exception) {
                    throw new FormatException(exception);
                } catch (Exception e) {
                    LOGGER.warn("Could not parse OME-XML metadata", e);
                }
                break;
            } else {
                addGlobalMeta(key, readString());
            }
        }
        in.seek(current_position);
    }
    if (stackPosition != 0) {
        core.clear();
        do {
            stackPosition = initStack(stackPosition);
        } while (stackPosition != 0);
    }
    if (ome_meta_data == null) {
        MetadataTools.populatePixels(metadataStore, this);
        for (int image = 0; image != core.size(); ++image) {
            CoreMetadata meta_data = core.get(image);
            final String name = meta_data.seriesMetadata.get("Name").toString();
            metadataStore.setImageName(name, image);
            @SuppressWarnings("unchecked") final List<Double> lengths = (List<Double>) meta_data.seriesMetadata.get("Lengths");
            if (lengths.size() > 0) {
                double lengthX = Math.abs(lengths.get(0));
                if (lengthX < 0.01) {
                    lengthX *= 1000000;
                }
                if (lengthX > 0) {
                    Length physicalSizeX = FormatTools.getPhysicalSizeX(lengthX / meta_data.sizeX, UNITS.MICROMETER);
                    if (physicalSizeX != null) {
                        metadataStore.setPixelsPhysicalSizeX(physicalSizeX, image);
                    }
                }
            }
            if (lengths.size() > 1) {
                double lengthY = Math.abs(lengths.get(1));
                if (lengthY < 0.01) {
                    lengthY *= 1000000;
                }
                if (lengthY > 0) {
                    Length physicalSizeY = FormatTools.getPhysicalSizeY(lengthY / meta_data.sizeY, UNITS.MICROMETER);
                    if (physicalSizeY != null) {
                        metadataStore.setPixelsPhysicalSizeY(physicalSizeY, image);
                    }
                }
            }
            if (lengths.size() > 2) {
                double lengthZ = Math.abs(lengths.get(2));
                if (lengthZ < 0.01) {
                    lengthZ *= 1000000;
                }
                if (lengthZ > 0) {
                    Length physicalSizeZ = FormatTools.getPhysicalSizeZ(lengthZ / meta_data.sizeZ, UNITS.MICROMETER);
                    if (physicalSizeZ != null) {
                        metadataStore.setPixelsPhysicalSizeZ(physicalSizeZ, image);
                    }
                }
            }
        }
    }
}
Also used : PositiveInteger(ome.xml.model.primitives.PositiveInteger) ServiceFactory(loci.common.services.ServiceFactory) DependencyException(loci.common.services.DependencyException) CoreMetadata(loci.formats.CoreMetadata) OMEXMLService(loci.formats.services.OMEXMLService) DataFormatException(java.util.zip.DataFormatException) FormatException(loci.formats.FormatException) ServiceException(loci.common.services.ServiceException) DependencyException(loci.common.services.DependencyException) DataFormatException(java.util.zip.DataFormatException) MissingLibraryException(loci.formats.MissingLibraryException) FormatException(loci.formats.FormatException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) ServiceException(loci.common.services.ServiceException) Length(ome.units.quantity.Length) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) MissingLibraryException(loci.formats.MissingLibraryException) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 7 with OMEXMLMetadata

use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.

the class OMETiffReader method isSingleFile.

// -- IFormatReader API methods --
/* @see loci.formats.IFormatReader#isSingleFile(String) */
@Override
public boolean isSingleFile(String id) throws FormatException, IOException {
    // companion files in a binary-only dataset should always have additional files
    if (checkSuffix(id, "companion.ome")) {
        return false;
    }
    // parse and populate OME-XML metadata
    String fileName = new Location(id).getAbsoluteFile().getAbsolutePath();
    RandomAccessInputStream ras = new RandomAccessInputStream(fileName, 16);
    TiffParser tp = new TiffParser(ras);
    IFD ifd = tp.getFirstIFD();
    long[] ifdOffsets = tp.getIFDOffsets();
    ras.close();
    String xml = ifd.getComment();
    if (service == null)
        setupService();
    OMEXMLMetadata meta;
    try {
        meta = service.createOMEXMLMetadata(xml);
        metaFile = new Location(id).getAbsolutePath();
    } catch (ServiceException se) {
        throw new FormatException(se);
    }
    if (meta.getRoot() == null) {
        throw new FormatException("Could not parse OME-XML from TIFF comment");
    }
    int nImages = 0;
    for (int i = 0; i < meta.getImageCount(); i++) {
        int nChannels = meta.getChannelCount(i);
        if (nChannels == 0)
            nChannels = 1;
        int z = meta.getPixelsSizeZ(i).getValue().intValue();
        int t = meta.getPixelsSizeT(i).getValue().intValue();
        nImages += z * t * nChannels;
    }
    return nImages > 0 && nImages <= ifdOffsets.length;
}
Also used : ServiceException(loci.common.services.ServiceException) IFD(loci.formats.tiff.IFD) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream) FormatException(loci.formats.FormatException) Location(loci.common.Location)

Example 8 with OMEXMLMetadata

use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.

the class ROIHandler method openROIs.

/**
 * Opens the rois and converts them into ImageJ Rois.
 *
 * @param retrieve The OMEXML store.
 * @param images The imageJ object.
 * @param isOMERO <code>true</code> if data stored in OMERO,
 *        <code>false</code> otherwise.
 * @param roisMode Determines whether to import Rois to overlay or RoiManager
 */
public static void openROIs(IMetadata retrieve, ImagePlus[] images, boolean isOMERO, String roisMode) {
    if (!(retrieve instanceof OMEXMLMetadata))
        return;
    int nextRoi = 0;
    RoiManager manager = RoiManager.getInstance();
    OME root = (OME) retrieve.getRoot();
    Roi roi;
    Float sw;
    Color sc;
    Color fc;
    int imageCount = images.length;
    for (int imageNum = 0; imageNum < imageCount; imageNum++) {
        int roiCount = root.sizeOfROIList();
        if (roiCount > 0 && manager == null && roisMode.equals(ImporterOptions.ROIS_MODE_MANAGER)) {
            manager = new RoiManager();
        }
        for (int roiNum = 0; roiNum < roiCount; roiNum++) {
            Union shapeSet = root.getROI(roiNum).getUnion();
            int shapeCount = shapeSet.sizeOfShapeList();
            for (int shape = 0; shape < shapeCount; shape++) {
                Shape shapeObject = shapeSet.getShape(shape);
                roi = null;
                sw = null;
                sc = null;
                fc = null;
                int c = 0;
                int z = 0;
                int t = 0;
                if (shapeObject instanceof Ellipse) {
                    Ellipse ellipse = (Ellipse) shapeObject;
                    int cx = ellipse.getX().intValue();
                    int cy = ellipse.getY().intValue();
                    int rx = ellipse.getRadiusX().intValue();
                    int ry = ellipse.getRadiusY().intValue();
                    roi = new OvalRoi(cx - rx, cy - ry, rx * 2, ry * 2);
                    if (ellipse.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = ellipse.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (ellipse.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = ellipse.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (ellipse.getStrokeWidth() != null) {
                        sw = ellipse.getStrokeWidth().value().floatValue();
                    }
                } else if (shapeObject instanceof ome.xml.model.Line) {
                    ome.xml.model.Line line = (ome.xml.model.Line) shapeObject;
                    int x1 = line.getX1().intValue();
                    int x2 = line.getX2().intValue();
                    int y1 = line.getY1().intValue();
                    int y2 = line.getY2().intValue();
                    roi = new Line(x1, y1, x2, y2);
                    if (line.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = line.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (line.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = line.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (line.getStrokeWidth() != null) {
                        sw = line.getStrokeWidth().value().floatValue();
                    }
                } else if (shapeObject instanceof Point) {
                    Point point = (Point) shapeObject;
                    int x = point.getX().intValue();
                    int y = point.getY().intValue();
                    roi = new PointRoi(x, y);
                    if (point.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = point.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (point.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = point.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (point.getStrokeWidth() != null) {
                        sw = point.getStrokeWidth().value().floatValue();
                    }
                } else if (shapeObject instanceof Polyline) {
                    Polyline polyline = (Polyline) shapeObject;
                    String points = polyline.getPoints();
                    int[][] coordinates = parsePoints(points);
                    roi = new PolygonRoi(coordinates[0], coordinates[1], coordinates[0].length, Roi.POLYLINE);
                    if (polyline.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = polyline.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (polyline.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = polyline.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (polyline.getStrokeWidth() != null) {
                        sw = polyline.getStrokeWidth().value().floatValue();
                    }
                } else if (shapeObject instanceof Polygon) {
                    Polygon polygon = (Polygon) shapeObject;
                    String points = polygon.getPoints();
                    int[][] coordinates = parsePoints(points);
                    roi = new PolygonRoi(coordinates[0], coordinates[1], coordinates[0].length, Roi.POLYGON);
                    if (polygon.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = polygon.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (polygon.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = polygon.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (polygon.getStrokeWidth() != null) {
                        sw = polygon.getStrokeWidth().value().floatValue();
                    }
                } else if (shapeObject instanceof ome.xml.model.Label) {
                    // add support for TextROI's
                    ome.xml.model.Label label = (ome.xml.model.Label) shapeObject;
                    double x = label.getX().doubleValue();
                    double y = label.getY().doubleValue();
                    String labelText = label.getText();
                    int size = label.getFontSize().value().intValue();
                    Font font = new Font(labelText, Font.PLAIN, size);
                    roi = new TextRoi((int) x, (int) y, labelText, font);
                    if (label.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = label.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (label.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = label.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (label.getStrokeWidth() != null) {
                        sw = label.getStrokeWidth().value().floatValue();
                    }
                } else if (shapeObject instanceof ome.xml.model.Rectangle) {
                    ome.xml.model.Rectangle rectangle = (ome.xml.model.Rectangle) shapeObject;
                    int x = rectangle.getX().intValue();
                    int y = rectangle.getY().intValue();
                    int w = rectangle.getWidth().intValue();
                    int h = rectangle.getHeight().intValue();
                    roi = new Roi(x, y, w, h);
                    if (rectangle.getStrokeColor() != null) {
                        ome.xml.model.primitives.Color StrokeColor = rectangle.getStrokeColor();
                        sc = new Color(StrokeColor.getRed(), StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha());
                        if (isOMERO) {
                            sc = new Color(StrokeColor.getGreen(), StrokeColor.getBlue(), StrokeColor.getAlpha(), StrokeColor.getRed());
                        }
                    }
                    if (rectangle.getFillColor() != null) {
                        ome.xml.model.primitives.Color FillColor = rectangle.getFillColor();
                        fc = new Color(FillColor.getRed(), FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha());
                        if (isOMERO) {
                            fc = new Color(FillColor.getGreen(), FillColor.getBlue(), FillColor.getAlpha(), FillColor.getRed());
                        }
                    }
                    if (rectangle.getStrokeWidth() != null) {
                        sw = rectangle.getStrokeWidth().value().floatValue();
                    }
                }
                if (roi != null) {
                    String roiLabel = shapeObject.getText();
                    if (roiLabel == null) {
                        roiLabel = shapeObject.getID();
                    }
                    roi.setName(roiLabel);
                    if (Prefs.showAllSliceOnly) {
                        if (shapeObject.getTheC() != null) {
                            c = shapeObject.getTheC().getValue();
                        }
                        if (shapeObject.getTheZ() != null) {
                            z = shapeObject.getTheZ().getValue();
                        }
                        if (shapeObject.getTheT() != null) {
                            t = shapeObject.getTheT().getValue();
                        }
                        // ImageJ expects 1-based indexing, opposed to
                        // 0-based indexing in OME
                        // Roi positions differ between hyperstacks and normal stacks
                        ImagePlus imp = images[imageNum];
                        if (imp.getNChannels() > 1) {
                            c++;
                        }
                        if (imp.getNSlices() > 1) {
                            z++;
                        }
                        if (imp.getNFrames() > 1) {
                            t++;
                        }
                        if (c == 0)
                            c = 1;
                        if (t == 0)
                            t = 1;
                        if (z == 0)
                            z = 1;
                        if (imp.getNChannels() == 1 && imp.getNSlices() == 1) {
                            roi.setPosition(t);
                        } else if (imp.getNChannels() == 1 && imp.getNFrames() == 1) {
                            roi.setPosition(z);
                        } else if (imp.getNSlices() == 1 && imp.getNFrames() == 1) {
                            roi.setPosition(c);
                        } else if (imp.isHyperStack()) {
                            roi.setPosition(c, z, t);
                        }
                    }
                    if (sw == null) {
                        roi.setStrokeWidth((float) 1);
                    }
                    if (sw != null) {
                        if (sw == 0) {
                            sw = (float) 1;
                        }
                        roi.setStrokeWidth(sw);
                    }
                    if (sc != null) {
                        roi.setStrokeColor(sc);
                    }
                    if (roisMode.equals(ImporterOptions.ROIS_MODE_MANAGER)) {
                        manager.add(images[imageNum], roi, nextRoi++);
                    } else if (roisMode.equals(ImporterOptions.ROIS_MODE_OVERLAY)) {
                        Overlay overlay = images[imageNum].getOverlay();
                        if (overlay == null) {
                            overlay = new Overlay(roi);
                            images[imageNum].setOverlay(overlay);
                        } else {
                            overlay.add(roi);
                        }
                    }
                }
            }
        }
        if (roiCount > 0 && manager != null) {
            manager.setAlwaysOnTop(true);
            manager.runCommand("show all with labels");
        }
    }
}
Also used : Ellipse(ome.xml.model.Ellipse) Shape(ome.xml.model.Shape) Rectangle(java.awt.Rectangle) TextRoi(ij.gui.TextRoi) OvalRoi(ij.gui.OvalRoi) Union(ome.xml.model.Union) Font(java.awt.Font) PolygonRoi(ij.gui.PolygonRoi) Polygon(ome.xml.model.Polygon) Overlay(ij.gui.Overlay) PointRoi(ij.gui.PointRoi) OME(ome.xml.model.OME) Color(java.awt.Color) Point(ome.xml.model.Point) PolygonRoi(ij.gui.PolygonRoi) TextRoi(ij.gui.TextRoi) OvalRoi(ij.gui.OvalRoi) PointRoi(ij.gui.PointRoi) EllipseRoi(ij.gui.EllipseRoi) ShapeRoi(ij.gui.ShapeRoi) Roi(ij.gui.Roi) ImagePlus(ij.ImagePlus) Point(ome.xml.model.Point) RoiManager(ij.plugin.frame.RoiManager) Line(ij.gui.Line) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) Polyline(ome.xml.model.Polyline)

Example 9 with OMEXMLMetadata

use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.

the class FormatReader method setId.

/**
 * Initializes a reader from the input file name.
 *
 * Calls {@link #initFile(String id)} to initializes the input file, reads
 * all of the metadata and sets the reader up for reading planes.
 * The performance of this method depends on the format and can be up to
 * several minutes for large file sets.
 *
 *  @param id a {@link String} specifying the path to the file
 */
@Override
public void setId(String id) throws FormatException, IOException {
    LOGGER.debug("{} initializing {}", this.getClass().getSimpleName(), id);
    if (currentId == null || !new Location(id).getAbsolutePath().equals(new Location(currentId).getAbsolutePath())) {
        initFile(id);
        MetadataStore store = getMetadataStore();
        if (saveOriginalMetadata) {
            if (store instanceof OMEXMLMetadata) {
                setupService();
                Hashtable<String, Object> allMetadata = new Hashtable<String, Object>();
                allMetadata.putAll(metadata);
                for (int series = 0; series < getSeriesCount(); series++) {
                    String name = "Series " + series;
                    try {
                        String realName = ((IMetadata) store).getImageName(series);
                        if (realName != null && realName.trim().length() != 0) {
                            name = realName;
                        }
                    } catch (Exception e) {
                    }
                    setSeries(series);
                    MetadataTools.merge(getSeriesMetadata(), allMetadata, name + " ");
                }
                setSeries(0);
                service.populateOriginalMetadata((OMEXMLMetadata) store, allMetadata);
            }
        }
        if (store instanceof OMEXMLMetadata) {
            ((OMEXMLMetadata) store).resolveReferences();
            setupService();
            if (getMetadataOptions().isValidate()) {
                try {
                    String omexml = service.getOMEXML((MetadataRetrieve) store);
                    service.validateOMEXML(omexml);
                } catch (ServiceException | NullPointerException e) {
                    LOGGER.warn("OMEXMLService unable to create OME-XML metadata object.", e);
                }
            }
            for (int series = 0; series < getSeriesCount(); series++) {
                setSeries(series);
                if (getModuloZ().length() > 1 || getModuloC().length() > 1 || getModuloT().length() > 1) {
                    service.addModuloAlong((OMEXMLMetadata) store, core.get(series), series);
                }
            }
            setSeries(0);
        }
    }
}
Also used : Hashtable(java.util.Hashtable) ServiceException(loci.common.services.ServiceException) DependencyException(loci.common.services.DependencyException) EnumerationException(ome.xml.model.enums.EnumerationException) IOException(java.io.IOException) MetadataStore(loci.formats.meta.MetadataStore) IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) Location(loci.common.Location)

Example 10 with OMEXMLMetadata

use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.

the class MetadataTools method populatePixels.

/**
 * Populates the Pixels element of the given metadata store, using core
 * metadata from the given reader.  If the {@code doPlane} flag is set,
 * then the Plane elements will be populated as well. If the
 * {@code doImageName} flag is set, then the image name will be populated as
 * well.
 *
 * @param store       The metadata store whose Pixels should be populated
 * @param r           The format reader whose core metadata should be used
 * @param doPlane     Specifies whether Plane elements should be populated
 * @param doImageName Specifies whether the Image name should be populated
 */
public static void populatePixels(MetadataStore store, IFormatReader r, boolean doPlane, boolean doImageName) {
    if (store == null || r == null)
        return;
    int oldSeries = r.getSeries();
    for (int i = 0; i < r.getSeriesCount(); i++) {
        r.setSeries(i);
        String imageName = null;
        if (doImageName) {
            Location f = new Location(r.getCurrentFile());
            imageName = f.getName();
            if (r.getSeriesCount() > 1) {
                imageName += " #" + (i + 1);
            }
        }
        String pixelType = FormatTools.getPixelTypeString(r.getPixelType());
        populateMetadata(store, r.getCurrentFile(), i, imageName, r.isLittleEndian(), r.getDimensionOrder(), pixelType, r.getSizeX(), r.getSizeY(), r.getSizeZ(), r.getSizeC(), r.getSizeT(), r.getRGBChannelCount());
        store.setPixelsInterleaved(r.isInterleaved(), i);
        store.setPixelsSignificantBits(new PositiveInteger(r.getBitsPerPixel()), i);
        try {
            OMEXMLService service = new ServiceFactory().getInstance(OMEXMLService.class);
            if (service.isOMEXMLRoot(store.getRoot())) {
                MetadataStore baseStore = r.getMetadataStore();
                if (service.isOMEXMLMetadata(baseStore)) {
                    OMEXMLMetadata omeMeta;
                    try {
                        omeMeta = service.getOMEMetadata(service.asRetrieve(baseStore));
                        if (omeMeta.getTiffDataCount(i) == 0 && omeMeta.getPixelsBinDataCount(i) == 0) {
                            service.addMetadataOnly(omeMeta, i, i == 0);
                        }
                    } catch (ServiceException e) {
                        LOGGER.warn("Failed to add MetadataOnly", e);
                    }
                }
            }
        } catch (DependencyException exc) {
            LOGGER.warn("Failed to add MetadataOnly", exc);
        }
        if (doPlane) {
            for (int q = 0; q < r.getImageCount(); q++) {
                int[] coords = r.getZCTCoords(q);
                store.setPlaneTheZ(new NonNegativeInteger(coords[0]), i, q);
                store.setPlaneTheC(new NonNegativeInteger(coords[1]), i, q);
                store.setPlaneTheT(new NonNegativeInteger(coords[2]), i, q);
            }
        }
    }
    r.setSeries(oldSeries);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) PositiveInteger(ome.xml.model.primitives.PositiveInteger) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) Location(loci.common.Location)

Aggregations

OMEXMLMetadata (loci.formats.ome.OMEXMLMetadata)24 ServiceException (loci.common.services.ServiceException)12 ServiceFactory (loci.common.services.ServiceFactory)10 OMEXMLService (loci.formats.services.OMEXMLService)10 DependencyException (loci.common.services.DependencyException)9 IOException (java.io.IOException)8 FormatException (loci.formats.FormatException)8 MetadataStore (loci.formats.meta.MetadataStore)7 OMEXMLMetadataRoot (ome.xml.meta.OMEXMLMetadataRoot)7 Location (loci.common.Location)6 PositiveInteger (ome.xml.model.primitives.PositiveInteger)6 CoreMetadata (loci.formats.CoreMetadata)5 Length (ome.units.quantity.Length)5 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)5 Test (org.testng.annotations.Test)5 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3 MissingLibraryException (loci.formats.MissingLibraryException)3 Image (ome.xml.model.Image)3 EnumerationException (ome.xml.model.enums.EnumerationException)3