Search in sources :

Example 6 with TiffRational

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

the class BaseTiffReader method initMetadataStore.

/**
 * Populates the metadata store using the data parsed in
 * {@link #initStandardMetadata()} along with some further parsing done in
 * the method itself.
 *
 * All calls to the active <code>MetadataStore</code> should be made in this
 * method and <b>only</b> in this method. This is especially important for
 * sub-classes that override the getters for pixel set array size, etc.
 */
protected void initMetadataStore() throws FormatException {
    LOGGER.info("Populating OME metadata");
    // the metadata store we're working with
    MetadataStore store = makeFilterMetadata();
    IFD firstIFD = ifds.get(0);
    IFD exif = null;
    if (ifds.get(0).containsKey(IFD.EXIF)) {
        try {
            IFDList exifIFDs = tiffParser.getExifIFDs();
            if (exifIFDs.size() > 0) {
                exif = exifIFDs.get(0);
            }
            tiffParser.fillInIFD(exif);
        } catch (IOException e) {
            LOGGER.debug("Could not read EXIF IFDs", e);
        }
    }
    MetadataTools.populatePixels(store, this, exif != null);
    // format the creation date to ISO 8601
    String creationDate = getImageCreationDate();
    String date = DateTools.formatDate(creationDate, DATE_FORMATS, ".");
    if (creationDate != null && date == null) {
        LOGGER.warn("unknown creation date format: {}", creationDate);
    }
    creationDate = date;
    if (creationDate != null) {
        store.setImageAcquisitionDate(new Timestamp(creationDate), 0);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        // populate Experimenter
        String artist = firstIFD.getIFDTextValue(IFD.ARTIST);
        if (artist != null) {
            String firstName = null, lastName = null;
            int ndx = artist.indexOf(' ');
            if (ndx < 0)
                lastName = artist;
            else {
                firstName = artist.substring(0, ndx);
                lastName = artist.substring(ndx + 1);
            }
            String email = firstIFD.getIFDStringValue(IFD.HOST_COMPUTER);
            store.setExperimenterFirstName(firstName, 0);
            store.setExperimenterLastName(lastName, 0);
            store.setExperimenterEmail(email, 0);
            store.setExperimenterID(MetadataTools.createLSID("Experimenter", 0), 0);
        }
        store.setImageDescription(firstIFD.getComment(), 0);
        // set the X and Y pixel dimensions
        double pixX = firstIFD.getXResolution();
        double pixY = firstIFD.getYResolution();
        String unit = getResolutionUnitFromComment(firstIFD);
        Length sizeX = FormatTools.getPhysicalSizeX(pixX, unit);
        Length sizeY = FormatTools.getPhysicalSizeY(pixY, unit);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
        store.setPixelsPhysicalSizeZ(null, 0);
        if (exif != null) {
            if (exif.containsKey(IFD.EXPOSURE_TIME)) {
                Object exp = exif.get(IFD.EXPOSURE_TIME);
                if (exp instanceof TiffRational) {
                    Time exposure = new Time(((TiffRational) exp).doubleValue(), UNITS.SECOND);
                    for (int i = 0; i < getImageCount(); i++) {
                        store.setPlaneExposureTime(exposure, 0, i);
                    }
                }
            }
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) IFD(loci.formats.tiff.IFD) IFDList(loci.formats.tiff.IFDList) TiffRational(loci.formats.tiff.TiffRational) Time(ome.units.quantity.Time) IOException(java.io.IOException) Timestamp(ome.xml.model.primitives.Timestamp)

Example 7 with TiffRational

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

the class TiffRationalTest method testNotEqual.

@Test
public void testNotEqual() {
    TiffRational a = new TiffRational(1, 4);
    TiffRational b = new TiffRational(1, 5);
    assertTrue(!(a.equals(b)));
}
Also used : TiffRational(loci.formats.tiff.TiffRational) Test(org.testng.annotations.Test)

Example 8 with TiffRational

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

the class TiffRationalTest method testLessThan.

@Test
public void testLessThan() {
    TiffRational a = new TiffRational(1, 5);
    TiffRational b = new TiffRational(1, 4);
    assertEquals(-1, a.compareTo(b));
}
Also used : TiffRational(loci.formats.tiff.TiffRational) Test(org.testng.annotations.Test)

Example 9 with TiffRational

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

the class TiffRationalTest method testEqualObject.

@Test
public void testEqualObject() {
    TiffRational a = new TiffRational(1, 4);
    Object b = new Object();
    assertTrue(!(a.equals(b)));
}
Also used : TiffRational(loci.formats.tiff.TiffRational) Test(org.testng.annotations.Test)

Example 10 with TiffRational

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

the class TiffRationalTest method testGreaterThan.

@Test
public void testGreaterThan() {
    TiffRational a = new TiffRational(1, 4);
    TiffRational b = new TiffRational(1, 5);
    assertEquals(1, a.compareTo(b));
}
Also used : TiffRational(loci.formats.tiff.TiffRational) Test(org.testng.annotations.Test)

Aggregations

TiffRational (loci.formats.tiff.TiffRational)12 IFD (loci.formats.tiff.IFD)6 IFDList (loci.formats.tiff.IFDList)5 Test (org.testng.annotations.Test)5 IOException (java.io.IOException)3 FormatException (loci.formats.FormatException)3 PhotoInterp (loci.formats.tiff.PhotoInterp)3 Length (ome.units.quantity.Length)3 RandomAccessInputStream (loci.common.RandomAccessInputStream)2 CoreMetadata (loci.formats.CoreMetadata)2 MetadataStore (loci.formats.meta.MetadataStore)2 Timestamp (ome.xml.model.primitives.Timestamp)2 ArrayList (java.util.ArrayList)1 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)1 TiffCompression (loci.formats.tiff.TiffCompression)1 TiffIFDEntry (loci.formats.tiff.TiffIFDEntry)1 TiffParser (loci.formats.tiff.TiffParser)1 Time (ome.units.quantity.Time)1