private void findTIFFs() throws IOException { Location baseFile = new Location(currentId).getAbsoluteFile(); Location parent = baseFile.getParentFile(); FilePattern pattern = new FilePattern(baseFile); String[] tiffs = pattern.getFiles(); NumericComparator comparator = new NumericComparator(); Arrays.sort(tiffs, comparator); Vector<String> validTIFFs = new Vector<String>(); for (String tiff : tiffs) { if (!new Location(tiff).exists()) { String base = tiff.substring(tiff.lastIndexOf(File.separator) + 1); base = base.substring(0, base.indexOf(".")); String suffix = tiff.substring(tiff.lastIndexOf(".")); while (base.length() < 3) { base = "0" + base; } Location test = new Location(parent, base + suffix); if (test.exists()) { tiff = test.getAbsolutePath(); } else continue; } validTIFFs.add(tiff); } files = validTIFFs.toArray(new String[validTIFFs.size()]); }
/* @see loci.formats.FormatReader#initFile(String) */ public void initFile(String id) throws FormatException, IOException { super.initFile(id); tiffReader = new MinimalTiffReader(); positions = new Vector<Position>(); LOGGER.info("Reading metadata file"); // find metadata.txt Location file = new Location(currentId).getAbsoluteFile(); Location parentFile = file.getParentFile(); String metadataFile = METADATA; if (file.exists()) { metadataFile = new Location(parentFile, METADATA).getAbsolutePath(); // look for other positions if (parentFile.getName().indexOf("Pos_") >= 0) { parentFile = parentFile.getParentFile(); String[] dirs = parentFile.list(true); Arrays.sort(dirs); for (String dir : dirs) { if (dir.indexOf("Pos_") >= 0) { Position pos = new Position(); Location posDir = new Location(parentFile, dir); pos.metadataFile = new Location(posDir, METADATA).getAbsolutePath(); positions.add(pos); } } } else { Position pos = new Position(); pos.metadataFile = metadataFile; positions.add(pos); } } core = new CoreMetadata[positions.size()]; for (int i = 0; i < positions.size(); i++) { core[i] = new CoreMetadata(); setSeries(i); parsePosition(i); } setSeries(0); populateMetadata(); }
/* Locate the experiment file given any file in set */ private String locateExperimentFile(String id) throws FormatException, IOException { if (!checkSuffix(id, "exp")) { Location parent = new Location(id).getAbsoluteFile().getParentFile(); if (checkSuffix(id, "tif")) parent = parent.getParentFile(); Location expFile = new Location(parent, EXPERIMENT_FILE); if (expFile.exists()) { return expFile.getAbsolutePath(); } throw new FormatException( "Could not find " + EXPERIMENT_FILE + " in " + parent.getAbsolutePath()); } return id; }
/* @see loci.formats.IFormatReader#isThisType(String, boolean) */ public boolean isThisType(String name, boolean open) { if (super.isThisType(name, open)) return true; if (!checkSuffix(name, "tif") && open) { Location current = new Location(name).getAbsoluteFile(); Location parent = current.getParentFile(); String tiff = current.getName(); int index = tiff.lastIndexOf("."); if (index >= 0) { tiff = tiff.substring(0, index); } tiff += ".tif"; Location tiffFile = new Location(parent, tiff); return tiffFile.exists() && isThisType(tiffFile.getAbsolutePath(), open); } return false; }
/* @see loci.formats.FormatReader#initFile(String) */ protected void initFile(String id) throws FormatException, IOException { super.initFile(id); if (!checkSuffix(id, "vsi")) { Location current = new Location(id).getAbsoluteFile(); Location parent = current.getParentFile(); parent = parent.getParentFile(); Location grandparent = parent.getParentFile(); String vsi = parent.getName(); vsi = vsi.substring(1, vsi.length() - 1) + ".vsi"; Location vsiFile = new Location(grandparent, vsi); if (!vsiFile.exists()) { throw new FormatException("Could not find .vsi file."); } else { id = vsiFile.getAbsolutePath(); } } parser = new TiffParser(id); ifds = parser.getIFDs(); RandomAccessInputStream vsi = new RandomAccessInputStream(id); vsi.order(parser.getStream().isLittleEndian()); vsi.seek(8); readTags(vsi); vsi.seek(parser.getStream().getFilePointer()); vsi.skipBytes(273); ArrayList<String> files = new ArrayList<String>(); Location file = new Location(id).getAbsoluteFile(); Location dir = file.getParentFile(); String name = file.getName(); name = name.substring(0, name.lastIndexOf(".")); Location pixelsDir = new Location(dir, "_" + name + "_"); String[] stackDirs = pixelsDir.list(true); if (stackDirs != null) { for (String f : stackDirs) { Location stackDir = new Location(pixelsDir, f); String[] pixelsFiles = stackDir.list(true); if (pixelsFiles != null) { for (String pixelsFile : pixelsFiles) { if (checkSuffix(pixelsFile, "ets")) { files.add(new Location(stackDir, pixelsFile).getAbsolutePath()); } } } } } files.add(file.getAbsolutePath()); usedFiles = files.toArray(new String[files.size()]); core = new CoreMetadata[files.size() - 1 + ifds.size()]; tileOffsets = new Long[files.size() - 1][]; rows = new int[files.size() - 1]; cols = new int[files.size() - 1]; nDimensions = new int[core.length]; IFDList exifs = parser.getExifIFDs(); compressionType = new int[core.length]; tileX = new int[core.length]; tileY = new int[core.length]; tileMap = new HashMap[core.length]; for (int s = 0; s < core.length; s++) { core[s] = new CoreMetadata(); } for (int s = 0; s < core.length; s++) { tileMap[s] = new HashMap<TileCoordinate, Integer>(); if (s == 0 && !hasFlattenedResolutions()) { core[s].resolutionCount = ifds.size() + (files.size() == 1 ? 0 : 1); } if (s < files.size() - 1) { setSeries(s); parseETSFile(files.get(s), s); core[s].littleEndian = compressionType[s] == RAW; core[s].interleaved = core[s].rgb; if (s == 0 && exifs.size() > 0) { IFD exif = exifs.get(0); int newX = exif.getIFDIntValue(IFD.PIXEL_X_DIMENSION); int newY = exif.getIFDIntValue(IFD.PIXEL_Y_DIMENSION); if (getSizeX() > newX || getSizeY() > newY) { core[s].sizeX = newX; core[s].sizeY = newY; } } setSeries(0); } else { IFD ifd = ifds.get(s - files.size() + 1); PhotoInterp p = ifd.getPhotometricInterpretation(); int samples = ifd.getSamplesPerPixel(); core[s].rgb = samples > 1 || p == PhotoInterp.RGB; core[s].sizeX = (int) ifd.getImageWidth(); core[s].sizeY = (int) ifd.getImageLength(); 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].interleaved = false; core[s].falseColor = false; core[s].thumbnail = s != 0; } core[s].metadataComplete = true; core[s].dimensionOrder = "XYCZT"; } vsi.close(); MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this); }
/* @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()); } } }