protected void put(String key, IFD ifd, int tag) {
   put(key, ifd.getIFDValue(tag));
 }
Example #2
0
  /* @see BaseTiffReader#initStandardMetadata() */
  @Override
  protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();

    CoreMetadata m = core.get(0);

    m.sizeZ = 0;
    m.sizeT = 0;

    MetadataLevel level = getMetadataOptions().getMetadataLevel();
    for (IFD ifd : ifds) {
      if (level != MetadataLevel.MINIMUM) {
        short[] tag1 = (short[]) ifd.getIFDValue(IMAGE_PRO_TAG_1);

        if (tag1 != null) {
          String seqId = "";
          for (int i = 0; i < tag1.length; i++) seqId = seqId + tag1[i];
          addGlobalMeta("Image-Pro SEQ ID", seqId);
        }
      }

      int tag2 = ifds.get(0).getIFDIntValue(IMAGE_PRO_TAG_2);

      if (tag2 != -1) {
        // should be one of these for every image plane
        m.sizeZ++;
        addGlobalMeta("Frame Rate", tag2);
      }

      addGlobalMeta("Number of images", getSizeZ());
    }

    if (getSizeZ() == 0) m.sizeZ = 1;
    if (getSizeT() == 0) m.sizeT = 1;

    if (getSizeZ() == 1 && getSizeT() == 1) {
      m.sizeZ = ifds.size();
    }

    // default values
    addGlobalMeta("frames", getSizeZ());
    addGlobalMeta("channels", super.getSizeC());
    addGlobalMeta("slices", getSizeT());

    // parse the description to get channels, slices and times where applicable
    String descr = ifds.get(0).getComment();
    metadata.remove("Comment");
    if (descr != null) {
      String[] lines = descr.split("\n");
      for (String token : lines) {
        token = token.trim();
        int eq = token.indexOf("=");
        if (eq == -1) eq = token.indexOf(":");
        if (eq != -1) {
          String label = token.substring(0, eq);
          String data = token.substring(eq + 1);
          addGlobalMeta(label, data);
          if (label.equals("channels")) m.sizeC = Integer.parseInt(data);
          else if (label.equals("frames")) {
            m.sizeT = Integer.parseInt(data);
          } else if (label.equals("slices")) {
            m.sizeZ = Integer.parseInt(data);
          }
        }
      }
    }

    if (isRGB() && getSizeC() != 3) m.sizeC *= 3;

    m.dimensionOrder = "XY";

    int maxNdx = 0, max = 0;
    int[] dims = {getSizeZ(), getSizeC(), getSizeT()};
    String[] axes = {"Z", "C", "T"};

    for (int i = 0; i < dims.length; i++) {
      if (dims[i] > max) {
        max = dims[i];
        maxNdx = i;
      }
    }

    m.dimensionOrder += axes[maxNdx];

    if (maxNdx != 1) {
      if (getSizeC() > 1) {
        m.dimensionOrder += "C";
        m.dimensionOrder += (maxNdx == 0 ? axes[2] : axes[0]);
      } else m.dimensionOrder += (maxNdx == 0 ? axes[2] : axes[0]) + "C";
    } else {
      if (getSizeZ() > getSizeT()) m.dimensionOrder += "ZT";
      else m.dimensionOrder += "TZ";
    }
  }