Search in sources :

Example 16 with PhotoInterp

use of loci.formats.tiff.PhotoInterp in project bioformats by openmicroscopy.

the class IonpathMIBITiffReader method initStandardMetadata.

// -- Internal BaseTiffReader API methods --
/* @see loci.formats.BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();
    ifds = tiffParser.getIFDs();
    int seriesIndex;
    String imageType = null;
    core.clear();
    for (int i = 0; i < ifds.size(); i++) {
        IFD ifd = ifds.get(i);
        Object description = ifd.get(IFD.IMAGE_DESCRIPTION);
        if (description == null) {
            throw new FormatException("Image description is mandatory.");
        }
        String imageDescription = null;
        if (description instanceof TiffIFDEntry) {
            Object value = tiffParser.getIFDValue((TiffIFDEntry) description);
            if (value != null) {
                imageDescription = value.toString();
            }
        } else if (description instanceof String) {
            imageDescription = (String) description;
        }
        JSONObject jsonDescription;
        try {
            jsonDescription = new JSONObject(imageDescription);
            imageType = jsonDescription.getString("image.type");
            if (imageType.equals("SIMS")) {
                String mass = jsonDescription.getString("channel.mass");
                if (mass == null) {
                    throw new FormatException("Channel masses are mandatory.");
                }
                String target = jsonDescription.getString("channel.target");
                channelIDs.add(mass);
                channelNames.add(target != null && target != "null" ? target : mass);
            }
        } catch (JSONException e) {
            throw new FormatException("Unexpected format in SIMS description JSON.");
        }
        if (seriesTypes.containsKey(imageType)) {
            if (!imageType.equals("SIMS")) {
                throw new FormatException("Only type 'SIMS' can have >1 image per file.");
            }
            seriesIndex = seriesTypes.get(imageType);
            CoreMetadata ms = core.get(seriesIndex);
            ms.sizeC += 1;
            ms.imageCount += 1;
        } else {
            seriesIndex = seriesTypes.size();
            seriesTypes.put(imageType, seriesIndex);
            seriesIFDs.add(i);
            core.add(new CoreMetadata());
            setSeries(seriesIndex);
            tiffParser.setDoCaching(true);
            tiffParser.fillInIFD(ifd);
            if (imageType.equals("SIMS")) {
                try {
                    Iterator<?> keySet = jsonDescription.keys();
                    while (keySet.hasNext()) {
                        String key = (String) keySet.next();
                        if (key.startsWith("mibi.")) {
                            simsDescription.put(key, jsonDescription.getString(key));
                        }
                    }
                } catch (JSONException e) {
                    throw new FormatException("Unexpected format in SIMS description JSON.");
                }
            }
            CoreMetadata ms = core.get(seriesIndex);
            PhotoInterp p = ifd.getPhotometricInterpretation();
            int samples = ifd.getSamplesPerPixel();
            ms.rgb = samples > 1 || p == PhotoInterp.RGB;
            ms.sizeX = (int) ifd.getImageWidth();
            ms.sizeY = (int) ifd.getImageLength();
            ms.sizeZ = 1;
            ms.sizeT = 1;
            ms.sizeC = ms.rgb ? samples : 1;
            ms.littleEndian = ifd.isLittleEndian();
            ms.indexed = p == PhotoInterp.RGB_PALETTE && (get8BitLookupTable() != null || get16BitLookupTable() != null);
            ms.imageCount = 1;
            ms.pixelType = ifd.getPixelType();
            ms.metadataComplete = true;
            ms.interleaved = false;
            ms.falseColor = false;
            ms.dimensionOrder = "XYCZT";
            ms.thumbnail = false;
            ms.imageCount = 1;
            if (imageType.equals("SIMS")) {
                ms.seriesMetadata = simsDescription;
            }
        }
    }
}
Also used : TiffIFDEntry(loci.formats.tiff.TiffIFDEntry) JSONObject(org.json.JSONObject) IFD(loci.formats.tiff.IFD) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) PhotoInterp(loci.formats.tiff.PhotoInterp) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException)

Example 17 with PhotoInterp

use of loci.formats.tiff.PhotoInterp in project bioformats by openmicroscopy.

the class ImaconReader method initStandardMetadata.

// -- Internal BaseTiffReader API methods --
/* @see BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();
    ifds = tiffParser.getIFDs();
    core.clear();
    for (int i = 0; i < ifds.size(); i++) {
        CoreMetadata ms = new CoreMetadata();
        core.add(ms);
        ms.imageCount = 1;
        IFD ifd = ifds.get(i);
        ifd.remove(PIXELS_TAG);
        tiffParser.fillInIFD(ifd);
        PhotoInterp photo = ifd.getPhotometricInterpretation();
        int samples = ifd.getSamplesPerPixel();
        ms.rgb = samples > 1 || photo == PhotoInterp.RGB || photo == PhotoInterp.CFA_ARRAY;
        if (photo == PhotoInterp.CFA_ARRAY)
            samples = 3;
        ms.sizeX = (int) ifd.getImageWidth();
        ms.sizeY = (int) ifd.getImageLength();
        ms.sizeZ = 1;
        ms.sizeC = isRGB() ? samples : 1;
        ms.sizeT = 1;
        ms.pixelType = ifd.getPixelType();
        ms.indexed = photo == PhotoInterp.RGB_PALETTE;
        ms.dimensionOrder = "XYCZT";
        ms.interleaved = false;
    }
    IFD firstIFD = ifds.get(0);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        String xml = firstIFD.getIFDTextValue(XML_TAG).trim();
        xml = xml.substring(xml.indexOf('<'));
        XMLTools.parseXML(xml, new ImaconHandler());
    }
    String[] creationInfo = firstIFD.getIFDTextValue(CREATOR_TAG).split("\n");
    if (creationInfo.length > 4) {
        experimenterName = creationInfo[4].trim();
    }
    if (creationInfo.length > 6) {
        imageName = creationInfo[6].trim();
    }
    if (creationInfo.length > 8) {
        creationDate = creationInfo[8].trim();
    }
    if (creationInfo.length > 10) {
        creationDate += " " + creationInfo[10].trim();
    }
}
Also used : IFD(loci.formats.tiff.IFD) PhotoInterp(loci.formats.tiff.PhotoInterp) CoreMetadata(loci.formats.CoreMetadata)

Example 18 with PhotoInterp

use of loci.formats.tiff.PhotoInterp in project bioformats by openmicroscopy.

the class LeicaSCNReader method initCoreMetadata.

// -- Internal BaseTiffReader API methods --
protected void initCoreMetadata(int s, int resolution) throws FormatException, IOException {
    ImageCollection c = handler.collection;
    Image i = handler.imageMap.get(s);
    if (c == null || i == null) {
        throw new FormatException("Error setting core metadata for image number " + s);
    }
    CoreMetadata ms = core.get(s);
    if (resolution == 0) {
        ms.resolutionCount = i.pixels.sizeR;
    }
    Dimension dimension = i.pixels.lookupDimension(0, 0, resolution);
    if (dimension == null) {
        throw new FormatException("No dimension information for subresolution=" + resolution);
    }
    IFD ifd = ifds.get(dimension.ifd);
    PhotoInterp pi = ifd.getPhotometricInterpretation();
    int samples = ifd.getSamplesPerPixel();
    ms.rgb = samples > 1 || pi == PhotoInterp.RGB;
    ms.sizeX = (int) dimension.sizeX;
    ms.sizeY = (int) dimension.sizeY;
    ms.sizeZ = (int) i.pixels.sizeZ;
    ms.sizeT = 1;
    ms.sizeC = ms.rgb ? samples : i.pixels.sizeC;
    if ((ifd.getImageWidth() != ms.sizeX) || (ifd.getImageLength() != ms.sizeY)) {
        throw new FormatException("IFD dimensions do not match XML dimensions for image " + s + ": x=" + ifd.getImageWidth() + ", " + ms.sizeX + ", y=" + ifd.getImageLength() + ", " + ms.sizeY);
    }
    ms.orderCertain = true;
    ms.littleEndian = ifd.isLittleEndian();
    ms.indexed = pi == PhotoInterp.RGB_PALETTE && (get8BitLookupTable() != null || get16BitLookupTable() != null);
    ms.imageCount = i.pixels.sizeZ * i.pixels.sizeC;
    ms.pixelType = ifd.getPixelType();
    ms.metadataComplete = true;
    ms.interleaved = false;
    ms.falseColor = false;
    ms.dimensionOrder = "XYCZT";
    ms.thumbnail = i.imageThumbnail == resolution;
}
Also used : IFD(loci.formats.tiff.IFD) PhotoInterp(loci.formats.tiff.PhotoInterp) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException)

Example 19 with PhotoInterp

use of loci.formats.tiff.PhotoInterp in project bioformats by openmicroscopy.

the class JPKReader method initStandardMetadata.

// -- Internal BaseTiffReader API methods --
/* @see loci.formats.BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();
    ifds = tiffParser.getIFDs();
    // repopulate core metadata
    int seriesCount = ifds.size() > 1 ? 2 : 1;
    core.clear();
    for (int s = 0; s < seriesCount; s++) {
        CoreMetadata ms = new CoreMetadata();
        core.add(ms);
        IFD ifd = ifds.get(s);
        tiffParser.fillInIFD(ifd);
        PhotoInterp p = ifd.getPhotometricInterpretation();
        int samples = ifd.getSamplesPerPixel();
        ms.rgb = samples > 1 || p == PhotoInterp.RGB;
        ms.sizeX = (int) ifd.getImageWidth();
        ms.sizeY = (int) ifd.getImageLength();
        ms.sizeZ = 1;
        ms.sizeT = s == 0 ? 1 : ifds.size() - 1;
        ms.sizeC = ms.rgb ? samples : 1;
        ms.littleEndian = ifd.isLittleEndian();
        ms.indexed = p == PhotoInterp.RGB_PALETTE && (get8BitLookupTable() != null || get16BitLookupTable() != null);
        ms.imageCount = s == 0 ? 1 : ifds.size() - 1;
        ms.pixelType = ifd.getPixelType();
        ms.metadataComplete = true;
        ms.interleaved = false;
        ms.falseColor = false;
        ms.dimensionOrder = "XYCZT";
        if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
            setSeries(s);
            for (Integer key : ifds.get(s).keySet()) {
                if (key >= 32848) {
                    addSeriesMeta("Tag " + key, ifds.get(s).get(key));
                }
            }
        }
    }
    setSeries(0);
}
Also used : IFD(loci.formats.tiff.IFD) PhotoInterp(loci.formats.tiff.PhotoInterp) CoreMetadata(loci.formats.CoreMetadata)

Aggregations

PhotoInterp (loci.formats.tiff.PhotoInterp)19 IFD (loci.formats.tiff.IFD)18 CoreMetadata (loci.formats.CoreMetadata)17 FormatException (loci.formats.FormatException)9 RandomAccessInputStream (loci.common.RandomAccessInputStream)7 IFDList (loci.formats.tiff.IFDList)7 TiffParser (loci.formats.tiff.TiffParser)6 ArrayList (java.util.ArrayList)5 Location (loci.common.Location)4 MetadataStore (loci.formats.meta.MetadataStore)4 IOException (java.io.IOException)3 TiffIFDEntry (loci.formats.tiff.TiffIFDEntry)3 TiffRational (loci.formats.tiff.TiffRational)3 Length (ome.units.quantity.Length)2 Timestamp (ome.xml.model.primitives.Timestamp)2 File (java.io.File)1 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1