Пример #1
0
  /**
   * Populates the metadata store using the data parsed in {@link #initStandardMetadata()} along
   * with some further parsing done in the method itself.
   *
   * <p>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;

    // populate Image

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

      PositiveFloat sizeX = FormatTools.getPhysicalSizeX(pixX);
      PositiveFloat sizeY = FormatTools.getPhysicalSizeY(pixY);

      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) {
            Double exposure = ((TiffRational) exp).doubleValue();
            for (int i = 0; i < getImageCount(); i++) {
              store.setPlaneExposureTime(exposure, 0, i);
            }
          }
        }
      }
    }
  }