/* @see BaseTiffReader#initStandardMetadata() */
  protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();

    delegate = new MinimalTiffReader();
    delegate.setId(currentId);

    exposureTimes = new ArrayList<Double>();

    String data = ifds.get(0).getComment();

    // remove magic string
    data = data.substring(data.indexOf("\n") + 1);

    date = data.substring(0, data.indexOf("\n"));
    data = data.substring(data.indexOf("\n") + 1);
    data = data.replaceAll("ReadFromDoc", "");

    IniParser parser = new IniParser();
    parser.setCommentDelimiter(";");

    IniList ini = parser.parseINI(new BufferedReader(new StringReader(data)));

    String objective = ini.getTable(" MICROSCOPE ").get("Objective");
    int space = objective.indexOf(" ");
    if (space != -1) {
      magnification = new Integer(objective.substring(0, space - 1));
      immersion = objective.substring(space + 1);
    }

    IniTable cameraTable = ini.getTable(" CAPTURE DEVICE ");
    binning = cameraTable.get("Binning") + "x" + cameraTable.get("Binning");
    cameraType = cameraTable.get("Camera Type");
    cameraName = cameraTable.get("Camera Name");
    core[0].bitsPerPixel = Integer.parseInt(cameraTable.get("Display Depth"));

    IniTable captureTable = ini.getTable(" CAPTURE ");
    int index = 1;
    for (int i = 0; i < getSizeC(); i++) {
      if (captureTable.get("c_Filter" + index) != null) {
        exposureTimes.add(new Double(captureTable.get("c_Expos" + index)));
      } else i--;
      index++;
    }

    IniTable calibrationTable = ini.getTable(" CALIBRATION ");
    String units = calibrationTable.get("units");
    scaling = Double.parseDouble(calibrationTable.get("factor"));

    core[0].imageCount *= getSizeC();
    core[0].rgb = false;

    if (ifds.get(0).containsKey(CUSTOM_BITS)) {
      core[0].bitsPerPixel = ifds.get(0).getIFDIntValue(CUSTOM_BITS);
    }

    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
      HashMap<String, String> iniMap = ini.flattenIntoHashMap();
      metadata.putAll(iniMap);
    }
  }
Beispiel #2
0
 /* @see loci.formats.IFormatReader#close(boolean) */
 public void close(boolean fileOnly) throws IOException {
   super.close(fileOnly);
   if (!fileOnly) {
     experimenterName = null;
     creationDate = null;
     imageName = null;
   }
 }
Beispiel #3
0
  /* @see BaseTiffReader#initStandardMetadata() */
  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();
    }
  }
  /* @see BaseTiffReader#initMetadataStore() */
  protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);

    if (date != null) {
      date = DateTools.formatDate(date, DATE_FORMAT);
      if (date != null) {
        store.setImageAcquisitionDate(new Timestamp(date), 0);
      }
    }

    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
      store.setImageDescription(MAGIC_STRING, 0);
      if (scaling > 0) {
        store.setPixelsPhysicalSizeX(new PositiveFloat(scaling), 0);
        store.setPixelsPhysicalSizeY(new PositiveFloat(scaling), 0);
      } else {
        LOGGER.warn("Expected positive value for PhysicalSize; got {}", scaling);
      }

      String instrument = MetadataTools.createLSID("Instrument", 0);
      store.setInstrumentID(instrument, 0);
      store.setImageInstrumentRef(instrument, 0);

      store.setObjectiveID(MetadataTools.createLSID("Objective", 0, 0), 0, 0);
      if (magnification > 0) {
        store.setObjectiveNominalMagnification(new PositiveInteger(magnification), 0, 0);
      } else {
        LOGGER.warn("Expected positive value for NominalMagnification; got {}", magnification);
      }
      store.setObjectiveImmersion(getImmersion(immersion), 0, 0);

      String detector = MetadataTools.createLSID("Detector", 0, 0);
      store.setDetectorID(detector, 0, 0);
      store.setDetectorModel(cameraType + " " + cameraName, 0, 0);
      store.setDetectorType(getDetectorType("CCD"), 0, 0);

      for (int i = 0; i < getSizeC(); i++) {
        store.setDetectorSettingsID(detector, 0, i);
        store.setDetectorSettingsBinning(getBinning(binning), 0, i);
      }

      for (int i = 0; i < getImageCount(); i++) {
        int[] zct = getZCTCoords(i);
        store.setPlaneExposureTime(exposureTimes.get(zct[1]) / 1000000, 0, i);
      }
    }
  }
 /* @see loci.formats.IFormatReader#close(boolean) */
 public void close(boolean fileOnly) throws IOException {
   super.close(fileOnly);
   if (delegate != null) delegate.close(fileOnly);
   if (!fileOnly) {
     delegate = null;
     date = null;
     magnification = null;
     immersion = null;
     cameraType = null;
     cameraName = null;
     binning = null;
     exposureTimes = null;
     scaling = 0d;
   }
 }
Beispiel #6
0
 /* @see loci.formats.IFormatReader#close(boolean) */
 @Override
 public void close(boolean fileOnly) throws IOException {
   super.close(fileOnly);
   if (!fileOnly) {
     imageName = null;
     imageDescription = null;
     date = null;
     userName = null;
     microscopeModel = null;
     stageX = stageY = stageZ = null;
     sizeX = sizeY = timeIncrement = null;
     detectors = null;
     magnification = null;
   }
 }
 /* @see loci.formats.FormatReader#initFile(String) */
 protected void initFile(String id) throws FormatException, IOException {
   if (!checkSuffix(id, "tif")) {
     Location parent = new Location(id).getAbsoluteFile().getParentFile();
     String[] list = parent.list(true);
     for (String f : list) {
       if (checkSuffix(f, "tif")) {
         String path = new Location(parent, f).getAbsolutePath();
         if (isThisType(path)) {
           id = path;
           break;
         }
       }
     }
   }
   super.initFile(id);
 }
  /* @see loci.formats.BaseTiffReader#initMetadataStore() */
  protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();

    MetadataStore store = makeFilterMetadata();

    for (int i = 0; i < getSeriesCount(); i++) {
      store.setImageName("Series " + (i + 1), i);
    }

    MetadataLevel level = getMetadataOptions().getMetadataLevel();
    if (level != MetadataLevel.MINIMUM) {
      if (level != MetadataLevel.NO_OVERLAYS) {
        try {
          parseROIs(store);
        } catch (IOException e) {
          LOGGER.debug("Could not parse ROIs", e);
        }
      }
    }
  }
Beispiel #9
0
  /* @see BaseTiffReader#initMetadataStore() */
  protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();

    MetadataStore store = makeFilterMetadata();

    if (creationDate != null) {
      creationDate = DateTools.formatDate(creationDate, "yyyyMMdd HHmmSSZ");
    }

    for (int i = 0; i < getSeriesCount(); i++) {
      String name = imageName;
      if (imageName.length() == 0) {
        name = "#" + (i + 1);
      } else {
        name += " #" + (i + 1);
      }
      store.setImageName(name, i);
      if (creationDate != null) {
        store.setImageAcquisitionDate(new Timestamp(creationDate), i);
      }
    }

    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
      if (experimenterName == null) experimenterName = "";

      int nameSpace = experimenterName.indexOf(" ");
      String firstName = nameSpace == -1 ? "" : experimenterName.substring(0, nameSpace);
      String lastName =
          nameSpace == -1 ? experimenterName : experimenterName.substring(nameSpace + 1);

      String experimenter = MetadataTools.createLSID("Experimenter", 0);

      store.setExperimenterID(experimenter, 0);
      store.setExperimenterFirstName(firstName, 0);
      store.setExperimenterLastName(lastName, 0);

      for (int i = 0; i < getSeriesCount(); i++) {
        store.setImageExperimenterRef(experimenter, i);
      }
    }
  }
  /* @see loci.formats.FormatReader#initFile(String) */
  protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);

    Vector<String> uniqueChannels = new Vector<String>();
    Vector<Double> uniqueZs = new Vector<Double>();
    Vector<Double> stageX = new Vector<Double>();
    Vector<Double> stageY = new Vector<Double>();

    String filename = id.substring(id.lastIndexOf(File.separator) + 1);
    filename = filename.substring(0, filename.indexOf("."));
    boolean integerFilename = true;
    try {
      Integer.parseInt(filename);
    } catch (NumberFormatException e) {
      integerFilename = false;
    }

    if (integerFilename
        && ifds.size() == 1
        && ifds.get(0).getIFDIntValue(IFD.NEW_SUBFILE_TYPE) == 2) {
      // look for other files in the dataset

      findTIFFs();

      String stageLabel = null;

      for (String tiff : files) {
        MetamorphHandler handler = new MetamorphHandler();
        parseFile(tiff, handler);

        String label = handler.getStageLabel();
        if (stageLabel == null) {
          stageLabel = label;
        } else if (!label.equals(stageLabel)) {
          break;
        }

        if (!uniqueChannels.contains(handler.getChannelName())) {
          uniqueChannels.add(handler.getChannelName());
        }

        Vector<Double> zPositions = handler.getZPositions();
        Double pos = Math.rint(zPositions.get(0));

        if (!uniqueZs.contains(pos)) {
          uniqueZs.add(pos);
        }
      }

      MetamorphHandler handler = new MetamorphHandler();
      parseFile(files[files.length - 1], handler);

      String lastStageLabel = handler.getStageLabel();
      int lastField = getField(lastStageLabel);
      int lastWellRow = getWellRow(lastStageLabel);
      int lastWellColumn = getWellColumn(lastStageLabel);

      int field = getField(stageLabel);
      int fieldRow = getWellRow(stageLabel);
      int fieldColumn = getWellColumn(stageLabel);

      wellCount = lastField - field + 1;
      fieldRowCount = lastWellRow - fieldRow + 1;
      fieldColumnCount = lastWellColumn - fieldColumn + 1;
      core[0].sizeC = uniqueChannels.size();
      core[0].sizeZ = uniqueZs.size();
    } else {
      files = new String[] {id};
      wellCount = 1;
      fieldRowCount = 1;
      fieldColumnCount = 1;
      core[0].sizeC = 0;
    }

    // parse XML comment

    MetamorphHandler handler = new MetamorphHandler(getGlobalMetadata());
    Vector<Double> xPositions = new Vector<Double>();
    Vector<Double> yPositions = new Vector<Double>();

    for (IFD ifd : ifds) {
      String xml = XMLTools.sanitizeXML(ifd.getComment());
      XMLTools.parseXML(xml, handler);

      double x = handler.getStagePositionX();
      double y = handler.getStagePositionY();

      if (xPositions.size() == 0) {
        xPositions.add(x);
        yPositions.add(y);
      } else {
        double previousX = xPositions.get(xPositions.size() - 1);
        double previousY = yPositions.get(yPositions.size() - 1);

        if (Math.abs(previousX - x) > 0.21 || Math.abs(previousY - y) > 0.21) {
          xPositions.add(x);
          yPositions.add(y);
        }
      }
    }

    if (xPositions.size() > 1) {
      fieldRowCount = xPositions.size();
    }

    Vector<Integer> wavelengths = handler.getWavelengths();
    Vector<Double> zPositions = handler.getZPositions();

    // calculate axis sizes

    Vector<Integer> uniqueC = new Vector<Integer>();
    for (Integer c : wavelengths) {
      if (!uniqueC.contains(c)) {
        uniqueC.add(c);
      }
    }
    int effectiveC = uniqueC.size();
    if (effectiveC == 0) effectiveC = 1;
    if (getSizeC() == 0) core[0].sizeC = 1;
    int samples = ifds.get(0).getSamplesPerPixel();
    core[0].sizeC *= effectiveC * samples;

    Vector<Double> uniqueZ = new Vector<Double>();
    for (Double z : zPositions) {
      if (!uniqueZ.contains(z)) uniqueZ.add(z);
    }
    if (getSizeZ() == 0) core[0].sizeZ = 1;
    core[0].sizeZ *= uniqueZ.size();

    int totalPlanes = files.length * ifds.size();
    effectiveC = getSizeC() / samples;
    core[0].sizeT =
        totalPlanes / (wellCount * fieldRowCount * fieldColumnCount * getSizeZ() * effectiveC);
    if (getSizeT() == 0) core[0].sizeT = 1;

    int seriesCount = wellCount * fieldRowCount * fieldColumnCount;

    if (seriesCount > 1 && getSizeZ() > totalPlanes / seriesCount) {
      core[0].sizeZ = 1;
      core[0].sizeT = totalPlanes / (seriesCount * getSizeT() * effectiveC);
    }

    core[0].imageCount = getSizeZ() * getSizeT() * effectiveC;

    if (seriesCount > 1) {
      CoreMetadata oldCore = core[0];
      core = new CoreMetadata[seriesCount];
      for (int i = 0; i < seriesCount; i++) {
        core[i] = oldCore;
      }
    }

    for (int s = 0; s < wellCount * fieldRowCount * fieldColumnCount; s++) {
      if (files.length > 1) {
        int[] lengths =
            new int[] {
              getSizeZ(),
              getEffectiveSizeC(),
              fieldColumnCount,
              fieldRowCount,
              wellCount,
              getSizeT()
            };

        Well well = getWell(s);
        int[] position = new int[] {0, 0, well.fieldCol, well.fieldRow, well.well, 0};

        int fileIndex = FormatTools.positionToRaster(lengths, position);
        parseFile(files[fileIndex], handler);

        stageX.add(handler.getStagePositionX());
        stageY.add(handler.getStagePositionY());
      } else {
        stageX.add(xPositions.get(s));
        stageY.add(yPositions.get(s));
      }
    }

    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);

    store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
    store.setPlateRowNamingConvention(NamingConvention.LETTER, 0);
    store.setPlateColumnNamingConvention(NamingConvention.NUMBER, 0);

    for (int well = 0; well < wellCount; well++) {
      store.setWellID(MetadataTools.createLSID("Well", 0, well), 0, well);
      store.setWellRow(new NonNegativeInteger(0), 0, well);
      store.setWellColumn(new NonNegativeInteger(well), 0, well);

      for (int row = 0; row < fieldRowCount; row++) {
        for (int col = 0; col < fieldColumnCount; col++) {
          int field = row * fieldColumnCount + col;
          String wellSampleID = MetadataTools.createLSID("WellSample", 0, well, field);
          store.setWellSampleID(wellSampleID, 0, well, field);

          int seriesIndex = getSeriesIndex(row, col, well);
          String imageID = MetadataTools.createLSID("Image", seriesIndex);
          store.setImageID(imageID, seriesIndex);
          store.setWellSampleImageRef(imageID, 0, well, field);
          store.setWellSampleIndex(new NonNegativeInteger(seriesIndex), 0, well, field);
        }
      }
    }

    for (int s = 0; s < seriesCount; s++) {
      setSeries(s);
      Well well = getWell(s);

      String name = handler.getImageName();
      if (seriesCount > 1) {
        name =
            "Field "
                + (char) (well.fieldRow + 'A')
                + (well.fieldCol + 1)
                + ", Well "
                + (well.well + 1)
                + ": "
                + name;
      }

      store.setImageName(name, s);

      String date = DateTools.formatDate(handler.getDate(), DateTools.ISO8601_FORMAT);
      store.setImageAcquiredDate(date, s);

      if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        Vector<String> timestamps = handler.getTimestamps();
        Vector<Double> exposures = handler.getExposures();

        for (int i = 0; i < timestamps.size(); i++) {
          long timestamp = DateTools.getTime(timestamps.get(i), DATE_FORMAT);
          addSeriesMeta("timestamp " + i, timestamp);
        }
        for (int i = 0; i < exposures.size(); i++) {
          addSeriesMeta("exposure time " + i + " (ms)", exposures.get(i).floatValue() * 1000);
        }

        long startDate = 0;
        if (timestamps.size() > 0) {
          startDate = DateTools.getTime(timestamps.get(0), DATE_FORMAT);
        }

        store.setImageDescription("", s);

        int image = 0;
        for (int c = 0; c < getEffectiveSizeC(); c++) {
          for (int t = 0; t < getSizeT(); t++) {
            store.setPlaneTheZ(new NonNegativeInteger(0), s, image);
            store.setPlaneTheC(new NonNegativeInteger(c), s, image);
            store.setPlaneTheT(new NonNegativeInteger(t), s, image);

            if (t < timestamps.size()) {
              String stamp = timestamps.get(t);
              long ms = DateTools.getTime(stamp, DATE_FORMAT);
              store.setPlaneDeltaT((ms - startDate) / 1000.0, s, image);
            }
            if (image < exposures.size()) {
              store.setPlaneExposureTime(exposures.get(image), s, image);
            }

            if (s < stageX.size()) {
              store.setPlanePositionX(stageX.get(s), s, image);
            }
            if (s < stageY.size()) {
              store.setPlanePositionY(stageY.get(s), s, image);
            }
            image++;
          }
        }

        store.setImagingEnvironmentTemperature(handler.getTemperature(), s);
        store.setPixelsPhysicalSizeX(new PositiveFloat(handler.getPixelSizeX()), s);
        store.setPixelsPhysicalSizeY(new PositiveFloat(handler.getPixelSizeY()), s);

        for (int c = 0; c < getEffectiveSizeC(); c++) {
          if (uniqueChannels.size() > c) {
            store.setChannelName(uniqueChannels.get(c), s, c);
          } else store.setChannelName(handler.getChannelName(), s, c);
        }
      }
    }
  }
Beispiel #11
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";
    }
  }
  /* @see loci.formats.in.BaseTiffReader#initStandardMetadata() */
  protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();

    ifds = tiffParser.getIFDs();
    for (IFD ifd : ifds) {
      tiffParser.fillInIFD(ifd);
    }

    String comment = ifds.get(0).getComment();
    String[] values = comment.split(";");
    for (String v : values) {
      int eq = v.indexOf("=");
      if (eq < 0) continue;
      String key = v.substring(0, eq).trim();
      String value = v.substring(eq + 1).trim();
      addGlobalMeta(key, value);

      if (key.equals("OverlapsXY")) {
        String[] overlapValues = value.split(" ");
        overlaps = new int[ifds.size() * 2];
        for (int i = 0; i < overlapValues.length; i++) {
          overlaps[i] = Integer.parseInt(overlapValues[i]);
        }
      }
    }

    core = new CoreMetadata[ifds.size()];

    for (int i = 0; i < core.length; i++) {
      setSeries(i);
      core[i] = new CoreMetadata();

      if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {}
    }
    setSeries(0);

    // repopulate core metadata

    for (int s = 0; s < core.length; s++) {
      IFD ifd = ifds.get(s);
      PhotoInterp p = ifd.getPhotometricInterpretation();
      int samples = ifd.getSamplesPerPixel();
      core[s].rgb = samples > 1 || p == PhotoInterp.RGB;

      long numTileRows = ifd.getTilesPerColumn() - 1;
      long numTileCols = ifd.getTilesPerRow() - 1;

      int overlapX = overlaps[s * 2];
      int overlapY = overlaps[s * 2 + 1];

      core[s].sizeX = (int) (ifd.getImageWidth() - (numTileCols * overlapX));
      core[s].sizeY = (int) (ifd.getImageLength() - (numTileRows * overlapY));
      core[s].sizeZ = 1;
      core[s].sizeT = 1;
      core[s].sizeC = core[s].rgb ? samples : 1;
      core[s].littleEndian = ifd.isLittleEndian();
      core[s].indexed =
          p == PhotoInterp.RGB_PALETTE
              && (get8BitLookupTable() != null || get16BitLookupTable() != null);
      core[s].imageCount = 1;
      core[s].pixelType = ifd.getPixelType();
      core[s].metadataComplete = true;
      core[s].interleaved = false;
      core[s].falseColor = false;
      core[s].dimensionOrder = "XYCZT";
      core[s].thumbnail = s > 0;
    }

    // look for all of the other associated metadata files

    files = new ArrayList<String>();

    Location baseFile = new Location(currentId).getAbsoluteFile();
    Location parent = baseFile.getParentFile();
    String name = baseFile.getName();
    if (name.indexOf(".") >= 0) {
      name = name.substring(0, name.indexOf(".") + 1);
    }

    roiFile = new Location(parent, name + "ROI").getAbsolutePath();
    roiDrawFile = new Location(parent, name + "ROI-draw").getAbsolutePath();

    String[] list = parent.list(true);
    for (String f : list) {
      if (!f.equals(baseFile.getName())) {
        files.add(new Location(parent, f).getAbsolutePath());
      }
    }
  }
 /* @see loci.formats.IFormatReader#close(boolean) */
 public void close(boolean fileOnly) throws IOException {
   super.close(fileOnly);
   if (!fileOnly) {
     files = null;
   }
 }
Beispiel #14
0
  /* @see BaseTiffReader#initMetadataStore() */
  @Override
  protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);

    if (date != null) {
      date = DateTools.formatDate(date, DATE_FORMAT);
      if (date != null) {
        store.setImageAcquisitionDate(new Timestamp(date), 0);
      }
    }

    if (imageName != null) {
      store.setImageName(imageName, 0);
    }

    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
      if (imageDescription != null) {
        store.setImageDescription(imageDescription, 0);
      }
      if (userName != null) {
        store.setExperimenterID(MetadataTools.createLSID("Experimenter", 0), 0);
        store.setExperimenterLastName(userName, 0);
      }
      if (microscopeModel != null) {
        String instrument = MetadataTools.createLSID("Instrument", 0);
        store.setInstrumentID(instrument, 0);
        store.setImageInstrumentRef(instrument, 0);
        store.setMicroscopeModel(microscopeModel, 0);
      }
      if (detectors != null && detectors.size() > 0) {
        String instrument = MetadataTools.createLSID("Instrument", 0);
        store.setInstrumentID(instrument, 0);
        store.setImageInstrumentRef(instrument, 0);

        for (int i = 0; i < detectors.size(); i++) {
          String detectorID = MetadataTools.createLSID("Detector", 0, i);
          store.setDetectorID(detectorID, 0, i);
          store.setDetectorModel(detectors.get(i), 0, i);
          store.setDetectorType(getDetectorType("Other"), 0, i);
        }
      }
      if (magnification != null) {
        store.setObjectiveID(MetadataTools.createLSID("Objective", 0, 0), 0, 0);
        store.setObjectiveNominalMagnification(magnification, 0, 0);
        store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
        store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
      }

      store.setStageLabelX(stageX, 0);
      store.setStageLabelY(stageY, 0);
      store.setStageLabelZ(stageZ, 0);
      store.setStageLabelName("", 0);

      Length physicalSizeX = FormatTools.getPhysicalSizeX(sizeX);
      Length physicalSizeY = FormatTools.getPhysicalSizeY(sizeY);

      if (physicalSizeX != null) {
        store.setPixelsPhysicalSizeX(physicalSizeX, 0);
      }
      if (physicalSizeY != null) {
        store.setPixelsPhysicalSizeY(physicalSizeY, 0);
      }
      if (timeIncrement != null) {
        store.setPixelsTimeIncrement(new Time(timeIncrement, UNITS.S), 0);
      }
    }
  }
Beispiel #15
0
  /* @see BaseTiffReader#initStandardMetadata() */
  @Override
  protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();

    boolean helios = ifds.get(0).containsKey(HELIOS_TAG);
    boolean titan = ifds.get(0).containsKey(TITAN_TAG);

    // Helios etc data might have a stray Titan tag
    if (titan && ifds.get(0).getIFDTextValue(TITAN_TAG).trim().isEmpty()) {
      titan = false;
    }

    // Titan data (always?) has an empty Helios tag as well, so the Titan tag is checked first
    String software = "S-FEG";
    if (titan) {
      software = "Titan";
    } else if (helios) {
      software = "Helios NanoLab";
    }
    addGlobalMeta("Software", software);

    int tagKey = SFEG_TAG;
    if (titan) {
      tagKey = TITAN_TAG;
    } else if (helios) {
      tagKey = HELIOS_TAG;
    }

    String tag = ifds.get(0).getIFDTextValue(tagKey);
    if (tag == null) {
      return;
    }
    tag = tag.trim();
    if (tag.isEmpty()) {
      return; // fall back to regular reader
    }
    // store metadata for later conversion to OME-XML
    if (tag.startsWith("<")) {
      XMLTools.parseXML(tag, new FEIHandler());
    } else {
      IniParser parser = new IniParser();
      IniList ini = parser.parseINI(new BufferedReader(new StringReader(tag)));
      detectors = new ArrayList<String>();

      if (helios) {
        IniTable userTable = ini.getTable("User");
        date = userTable.get("Date") + " " + userTable.get("Time");

        if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
          userName = userTable.get("User");

          IniTable systemTable = ini.getTable("System");
          if (systemTable == null) {
            systemTable = ini.getTable("SYSTEM");
          }
          if (systemTable != null) {
            microscopeModel = systemTable.get("SystemType");
          }

          IniTable beamTable = ini.getTable("Beam");
          if (beamTable != null) {
            String beamTableName = beamTable.get("Beam");
            if (beamTableName != null) {
              beamTable = ini.getTable(beamTableName);
            }
          }

          if (beamTable != null) {
            String beamX = beamTable.get("StageX");
            String beamY = beamTable.get("StageY");
            String beamZ = beamTable.get("StageZ");
            IniTable stageTable = ini.getTable("Stage");

            if (beamX != null) {
              final Double number = Double.valueOf(beamX);
              stageX = new Length(number, UNITS.REFERENCEFRAME);
            } else if (stageTable != null) {
              final Double number = Double.valueOf(stageTable.get("StageX"));
              stageX = new Length(number, UNITS.REFERENCEFRAME);
            }

            if (beamY != null) {
              final Double number = Double.valueOf(beamY);
              stageY = new Length(number, UNITS.REFERENCEFRAME);
            } else if (stageTable != null) {
              final Double number = Double.valueOf(stageTable.get("StageY"));
              stageY = new Length(number, UNITS.REFERENCEFRAME);
            }

            if (beamZ != null) {
              final Double number = Double.valueOf(beamZ);
              stageZ = new Length(number, UNITS.REFERENCEFRAME);
            } else if (stageTable != null) {
              final Double number = Double.valueOf(stageTable.get("StageZ"));
              stageZ = new Length(number, UNITS.REFERENCEFRAME);
            }
          }

          IniTable scanTable = ini.getTable("Scan");
          // physical sizes are stored in meters
          sizeX = new Double(scanTable.get("PixelWidth")) * 1000000;
          sizeY = new Double(scanTable.get("PixelHeight")) * 1000000;
          timeIncrement = new Double(scanTable.get("FrameTime"));
        }
      } else {
        IniTable dataTable = ini.getTable("DatabarData");
        imageName = dataTable.get("ImageName");
        imageDescription = dataTable.get("szUserText");

        String magnification = ini.getTable("Vector").get("Magnification");
        sizeX = new Double(magnification) * MAG_MULTIPLIER;
        sizeY = new Double(magnification) * MAG_MULTIPLIER;

        IniTable scanTable = ini.getTable("Vector.Sysscan");
        final Double posX = Double.valueOf(scanTable.get("PositionX"));
        final Double posY = Double.valueOf(scanTable.get("PositionY"));
        stageX = new Length(posX, UNITS.REFERENCEFRAME);
        stageY = new Length(posY, UNITS.REFERENCEFRAME);

        IniTable detectorTable = ini.getTable("Vector.Video.Detectors");
        int detectorCount = Integer.parseInt(detectorTable.get("NrDetectorsConnected"));
        for (int i = 0; i < detectorCount; i++) {
          detectors.add(detectorTable.get("Detector_" + i + "_Name"));
        }
      }

      // store everything else in the metadata hashtable

      if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        HashMap<String, String> iniMap = ini.flattenIntoHashMap();
        metadata.putAll(iniMap);
      }
    }
  }