/** @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); long planeSize = FormatTools.getPlaneSize(this); long offset = HEADER_SIZE + extHeaderSize + no * planeSize; if (offset + planeSize <= in.length() && offset >= 0) { in.seek(offset); readPlane(in, x, getSizeY() - h - y, w, h, buf); // reverse the order of the rows // planes are stored with the origin in the lower-left corner byte[] tmp = new byte[w * FormatTools.getBytesPerPixel(getPixelType())]; for (int row = 0; row < h / 2; row++) { int src = row * tmp.length; int dest = (h - row - 1) * tmp.length; System.arraycopy(buf, src, tmp, 0, tmp.length); System.arraycopy(buf, dest, buf, src, tmp.length); System.arraycopy(tmp, 0, buf, dest, tmp.length); } } return buf; }
/** @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); if (getCoreIndex() < core.length - ifds.size()) { int tileRows = rows[getCoreIndex()]; int tileCols = cols[getCoreIndex()]; Region image = new Region(x, y, w, h); int outputRow = 0, outputCol = 0; Region intersection = null; byte[] tileBuf = null; int pixel = getRGBChannelCount() * FormatTools.getBytesPerPixel(getPixelType()); int outputRowLen = w * pixel; for (int row = 0; row < tileRows; row++) { for (int col = 0; col < tileCols; col++) { int width = tileX[getCoreIndex()]; int height = tileY[getCoreIndex()]; Region tile = new Region(col * width, row * height, width, height); if (!tile.intersects(image)) { continue; } intersection = tile.intersection(image); int intersectionX = 0; if (tile.x < image.x) { intersectionX = image.x - tile.x; } tileBuf = decodeTile(no, row, col); int rowLen = pixel * (int) Math.min(intersection.width, width); int outputOffset = outputRow * outputRowLen + outputCol; for (int trow = 0; trow < intersection.height; trow++) { int realRow = trow + intersection.y - tile.y; int inputOffset = pixel * (realRow * width + intersectionX); System.arraycopy(tileBuf, inputOffset, buf, outputOffset, rowLen); outputOffset += outputRowLen; } outputCol += rowLen; } if (intersection != null) { outputRow += intersection.height; outputCol = 0; } } return buf; } else { int ifdIndex = getCoreIndex() - (usedFiles.length - 1); return parser.getSamples(ifds.get(ifdIndex), buf, x, y, w, h); } }
private void writePixels(String chunk, byte[] stream, int x, int y, int width, int height) throws FormatException, IOException { MetadataRetrieve r = getMetadataRetrieve(); int sizeC = getSamplesPerPixel(); String type = r.getPixelsType(series).toString(); int pixelType = FormatTools.pixelTypeFromString(type); boolean signed = FormatTools.isSigned(pixelType); if (!isFullPlane(x, y, width, height)) { throw new FormatException("APNGWriter does not support writing tiles."); } ByteArrayOutputStream s = new ByteArrayOutputStream(); s.write(chunk.getBytes()); if (chunk.equals("fdAT")) { s.write(DataTools.intToBytes(nextSequenceNumber++, false)); } DeflaterOutputStream deflater = new DeflaterOutputStream(s); int planeSize = stream.length / sizeC; int rowLen = stream.length / height; int bytesPerPixel = stream.length / (width * height * sizeC); byte[] rowBuf = new byte[rowLen]; for (int i = 0; i < height; i++) { deflater.write(0); if (interleaved) { if (littleEndian) { for (int col = 0; col < width * sizeC; col++) { int offset = (i * sizeC * width + col) * bytesPerPixel; int pixel = DataTools.bytesToInt(stream, offset, bytesPerPixel, littleEndian); DataTools.unpackBytes(pixel, rowBuf, col * bytesPerPixel, bytesPerPixel, false); } } else System.arraycopy(stream, i * rowLen, rowBuf, 0, rowLen); } else { int max = (int) Math.pow(2, bytesPerPixel * 8 - 1); for (int col = 0; col < width; col++) { for (int c = 0; c < sizeC; c++) { int offset = c * planeSize + (i * width + col) * bytesPerPixel; int pixel = DataTools.bytesToInt(stream, offset, bytesPerPixel, littleEndian); if (signed) { if (pixel < max) pixel += max; else pixel -= max; } int output = (col * sizeC + c) * bytesPerPixel; DataTools.unpackBytes(pixel, rowBuf, output, bytesPerPixel, false); } } } deflater.write(rowBuf); } deflater.finish(); byte[] b = s.toByteArray(); // write chunk length out.writeInt(b.length - 4); out.write(b); // write checksum out.writeInt(crc(b)); }
/** @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); if (getSizeC() == 1) { return super.openBytes(no, buf, x, y, w, h); } byte[] b = delegate.openBytes(no / getSizeC(), x, y, w, h); int bpp = FormatTools.getBytesPerPixel(getPixelType()); int c = getZCTCoords(no)[1]; ImageTools.splitChannels(b, buf, c, getSizeC(), bpp, false, isInterleaved(), w * h * bpp); return buf; }
@SuppressWarnings({"rawtypes", "unchecked"}) private void populatePlane(IFormatReader r, int no, byte[] plane, PlanarAccess planarAccess) { final int pixelType = r.getPixelType(); final int bpp = FormatTools.getBytesPerPixel(pixelType); final boolean fp = FormatTools.isFloatingPoint(pixelType); final boolean little = r.isLittleEndian(); Object planeArray = DataTools.makeDataArray(plane, bpp, fp, little); if (planeArray == plane) { // array was returned by reference; make a copy final byte[] planeCopy = new byte[plane.length]; System.arraycopy(plane, 0, planeCopy, 0, plane.length); planeArray = planeCopy; } planarAccess.setPlane(no, makeArray(planeArray)); }
/* @see loci.formats.FormatReader#initFile(String) */ protected void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); CoreMetadata m = core.get(0); m.littleEndian = true; in.order(isLittleEndian()); while (in.getFilePointer() < MAX_HEADER_SIZE) { readVariable(); } in.seek(pixelsOffset); m.sizeX = in.readShort(); pixelsOffset += 2; m.sizeY = getSizeX(); m.pixelType = FormatTools.UINT16; m.sizeZ = 1; m.sizeC = 1; m.sizeT = 1; m.imageCount = 1; m.dimensionOrder = "XYZCT"; MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this); if (date != null) { date = DateTools.formatDate(date, "MMM dd yyyy HH:mm:ssSSS"); if (date != null) { store.setImageAcquisitionDate(new Timestamp(date), 0); } } if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) { store.setImageDescription(comment, 0); PositiveFloat sizeX = FormatTools.getPhysicalSizeX((double) xSize / getSizeX()); PositiveFloat sizeY = FormatTools.getPhysicalSizeY((double) xSize / getSizeY()); if (sizeX != null) { store.setPixelsPhysicalSizeX(sizeX, 0); } if (sizeY != null) { store.setPixelsPhysicalSizeY(sizeY, 0); } } }
/* @see loci.formats.IFormatReader#getOptimalTileHeight() */ public int getOptimalTileHeight() { FormatTools.assertId(currentId, true, 1); if (tiffReader.getCurrentFile() == null) { setupReader(); } return tiffReader.getOptimalTileHeight(); }
/** @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { if (getSeriesCount() == 1) return super.openBytes(no, buf, x, y, w, h); int[] lengths = new int[] { getSizeZ(), getEffectiveSizeC(), fieldColumnCount, fieldRowCount, wellCount, getSizeT() }; int[] zct = getZCTCoords(no); Well well = getWell(getSeries()); int[] position = new int[] {zct[0], zct[1], well.fieldCol, well.fieldRow, well.well, zct[2]}; int fileIndex = FormatTools.positionToRaster(lengths, position); RandomAccessInputStream s = null; if (fileIndex < files.length) { s = new RandomAccessInputStream(files[fileIndex]); } else { s = new RandomAccessInputStream(files[0]); } TiffParser parser = new TiffParser(s); IFD ifd = files.length == 1 ? ifds.get(getSeries() * getImageCount() + no) : parser.getFirstIFD(); parser.getSamples(ifd, buf, x, y, w, h); s.close(); return buf; }
/** @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); String file = getFilename(getSeries(), no); int field = getSeries() % (fieldRows * fieldCols); int fieldRow = field / fieldCols; int fieldCol = field % fieldCols; if (file != null) { try { reader.setId(file); if (fieldRows * fieldCols == 1) { reader.openBytes(0, buf, x, y, w, h); } else { // fields are stored together in a single image, // so we need to split them up int fx = x + (fieldCol * getSizeX()); int fy = y + (fieldRow * getSizeY()); reader.openBytes(0, buf, fx, fy, w, h); } } catch (FormatException e) { LOGGER.debug("Could not read file " + file, e); return buf; } catch (IOException e) { LOGGER.debug("Could not read file " + file, e); return buf; } } return buf; }
public int hashCode() { int[] lengths = new int[coordinate.length]; lengths[0] = rows[getSeries()]; lengths[1] = cols[getSeries()]; for (String dim : dimensionOrdering.keySet()) { int index = dimensionOrdering.get(dim) + 2; if (dim.equals("Z")) { lengths[index] = getSizeZ(); } else if (dim.equals("C")) { lengths[index] = getEffectiveSizeC(); } else if (dim.equals("T")) { lengths[index] = getSizeT(); } } for (int i = 0; i < lengths.length; i++) { if (lengths[i] == 0) { lengths[i] = 1; } } return FormatTools.positionToRaster(lengths, coordinate); }
/** @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); tiffParser.getSamples(ifds.get(getSeries()), buf, x, y, w, h); return buf; }
/** @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); in.seek(pixelsOffset); readPlane(in, x, y, w, h, buf); return buf; }
/* @see loci.formats.IFormatReader#getOptimalTileHeight() */ public int getOptimalTileHeight() { FormatTools.assertId(currentId, true, 1); try { return (int) ifds.get(getSeries()).getTileLength(); } catch (FormatException e) { LOGGER.debug("", e); } return super.getOptimalTileHeight(); }
/* @see loci.formats.IFormatReader#getSeriesUsedFiles(boolean) */ public String[] getSeriesUsedFiles(boolean noPixels) { FormatTools.assertId(currentId, true, 1); if (noPixels) { return files.toArray(new String[files.size()]); } String[] allFiles = new String[files.size() + 1]; files.toArray(allFiles); allFiles[allFiles.length - 1] = currentId; return allFiles; }
/** @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); String file = positions.get(getSeries()).getFile(no); if (file != null && new Location(file).exists()) { tiffReader.setId(file); return tiffReader.openBytes(0, buf, x, y, w, h); } LOGGER.warn("File for image #{} ({}) is missing.", no, file); return buf; }
/* @see loci.formats.IFormatHandler#openThumbBytes(int) */ public byte[] openThumbBytes(int no) throws FormatException, IOException { FormatTools.assertId(currentId, true, 1); int currentSeries = getSeries(); int thumbSize = getThumbSizeX() * getThumbSizeY() * FormatTools.getBytesPerPixel(getPixelType()) * getRGBChannelCount(); if (getCoreIndex() >= usedFiles.length - 1 || usedFiles.length >= core.length) { return super.openThumbBytes(no); } setSeries(usedFiles.length); byte[] thumb = FormatTools.openThumbBytes(this, 0); setSeries(currentSeries); if (thumb.length == thumbSize) { return thumb; } return super.openThumbBytes(no); }
/* @see loci.formats.IFormatReader#getOptimalTileHeight() */ public int getOptimalTileHeight() { FormatTools.assertId(currentId, true, 1); if (getCoreIndex() < core.length - ifds.size()) { return tileY[getCoreIndex()]; } int ifdIndex = getCoreIndex() - (usedFiles.length - 1); try { return (int) ifds.get(ifdIndex).getTileLength(); } catch (FormatException e) { LOGGER.debug("Could not retrieve tile height", e); } return super.getOptimalTileHeight(); }
@Override public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.assertId(currentId, true, 1); FormatTools.checkPlaneNumber(this, no); FormatTools.checkBufferSize(this, buf.length, w, h); final int[] zct = FormatTools.getZCTCoords(this, no); final byte[] plane; try { plane = store.getPlane(zct[0], zct[1], zct[2]); } catch (ServerError e) { throw new FormatException(e); } RandomAccessInputStream s = new RandomAccessInputStream(plane); readPlane(s, x, y, w, h, buf); s.close(); return buf; }
/** @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); int[] zct = getZCTCoords(no); int channel = zct[1]; readers[channel].setId(ndpiFiles[channel]); int cIndex = channel < readers[channel].getSizeC() ? channel : 0; int plane = readers[channel].getIndex(zct[0], cIndex, zct[2]); readers[channel].openBytes(plane, buf, x, y, w, h); return buf; }
/* @see loci.formats.IFormatHandler#setId(String) */ public void setId(String id) throws FormatException, IOException { super.setId(id); if (out.length() == 0) { MetadataRetrieve r = getMetadataRetrieve(); int width = r.getPixelsSizeX(series).getValue().intValue(); int height = r.getPixelsSizeY(series).getValue().intValue(); int bytesPerPixel = FormatTools.getBytesPerPixel(r.getPixelsType(series).toString()); int nChannels = getSamplesPerPixel(); boolean indexed = getColorModel() != null && (getColorModel() instanceof IndexColorModel); littleEndian = !r.getPixelsBinDataBigEndian(series, 0); // write 8-byte PNG signature out.write(PNG_SIG); // write IHDR chunk out.writeInt(13); byte[] b = new byte[17]; b[0] = 'I'; b[1] = 'H'; b[2] = 'D'; b[3] = 'R'; DataTools.unpackBytes(width, b, 4, 4, false); DataTools.unpackBytes(height, b, 8, 4, false); b[12] = (byte) (bytesPerPixel * 8); if (indexed) b[13] = (byte) 3; else if (nChannels == 1) b[13] = (byte) 0; else if (nChannels == 2) b[13] = (byte) 4; else if (nChannels == 3) b[13] = (byte) 2; else if (nChannels == 4) b[13] = (byte) 6; b[14] = (byte) 0; b[15] = (byte) 0; b[16] = (byte) 0; out.write(b); out.writeInt(crc(b)); // write acTL chunk out.writeInt(8); out.writeBytes("acTL"); numFramesPointer = out.getFilePointer(); out.writeInt(0); out.writeInt(0); out.writeInt(0); // save a place for the CRC } }
public void populateMetadataStore(String[] jsonData) throws FormatException, IOException { FormatTools.assertId(currentId, false, 1); currentId = "in-memory-json"; core = new CoreMetadata[jsonData.length]; positions = new Vector<Position>(); for (int pos = 0; pos < jsonData.length; pos++) { core[pos] = new CoreMetadata(); Position p = new Position(); p.metadataFile = "Position #" + (pos + 1); positions.add(p); setSeries(pos); parsePosition(jsonData[pos], pos); } setSeries(0); populateMetadata(); }
/* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */ public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 4; if (!FormatTools.validStream(stream, blockLen, false)) return false; byte[] signature = new byte[blockLen]; stream.read(signature); if (signature[0] != (byte) 0xff || signature[1] != (byte) 0xd8 || signature[2] != (byte) 0xff || ((int) signature[3] & 0xf0) == 0) { return false; } return true; }
/** @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { if (getSeriesCount() == 1) { return super.openBytes(no, buf, x, y, w, h); } FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); tiffParser.getSamples( ifds.get(series), buf, x, y, w, h, overlaps[getSeries() * 2], overlaps[getSeries() * 2 + 1]); return buf; }
/* @see loci.formats.IFormatReader#getSeriesUsedFiles(boolean) */ public String[] getSeriesUsedFiles(boolean noPixels) { FormatTools.assertId(currentId, true, 1); Vector<String> files = new Vector<String>(); for (String file : metadataFiles) { if (file != null) files.add(file); } if (!noPixels && tiffs != null) { int well = getSeries() / (fieldRows * fieldCols); for (int i = 0; i < tiffs[well].length; i++) { files.add(tiffs[well][i]); } } return files.toArray(new String[files.size()]); }
/* @see loci.formats.IFormatReader#getSeriesUsedFiles(boolean) */ public String[] getSeriesUsedFiles(boolean noPixels) { FormatTools.assertId(currentId, true, 1); Vector<String> files = new Vector<String>(); for (Position pos : positions) { files.add(pos.metadataFile); if (pos.xmlFile != null) { files.add(pos.xmlFile); } if (!noPixels) { for (String tiff : pos.tiffs) { if (new Location(tiff).exists()) { files.add(tiff); } } } } return files.toArray(new String[files.size()]); }
/** * Obtains an object which represents a given sub-image of a plane within the file. * * @param id The path to the file. * @param planeNumber The plane or section within the file to obtain. * @param buf Pre-allocated buffer which has a <i>length</i> that can fit the byte count of the * sub-image. * @param x X coordinate of the upper-left corner of the sub-image * @param y Y coordinate of the upper-left corner of the sub-image * @param w width of the sub-image * @param h height of the sub-image * @return an object which represents the sub-image of the plane. * @throws FormatException If there is an error parsing the file. * @throws IOException If there is an error reading from the file or acquiring permissions to read * the file. */ public PixelData openPlane2D(String id, int planeNumber, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { // FIXME: HACK! The ChannelSeparator isn't exactly what one would call // "complete" so we have to work around the fact that it still copies // all of the plane data (all three channels) from the file if the file // is RGB. ByteBuffer plane; if (iReader.isRGB() || isLeicaReader()) { // System.err.println("RGB, not using cached buffer."); byte[] bytePlane = openBytes(planeNumber, x, y, w, h); plane = ByteBuffer.wrap(bytePlane); } else { // System.err.println("Not RGB, using cached buffer."); plane = ByteBuffer.wrap(openBytes(planeNumber, buf, x, y, w, h)); } plane.order(isLittleEndian() ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN); return new PixelData(FormatTools.getPixelTypeString(getPixelType()), plane); }
@BeforeMethod public void setUp() throws Exception { fullPlaneCallIndex = 1; // No mapping. // Location.mapId(TEST_FILE, TEST_FILE); reader = new FakeReader(); try { String uuid = UUID.randomUUID().toString(); idDir = new File(System.getProperty("java.io.tmpdir"), uuid); idDir.mkdirs(); File tempFile = new File(idDir, TEST_FILE); tempFile.createNewFile(); id = tempFile.getAbsolutePath(); reader.setId(id); sizeX = reader.getSizeX(); sizeY = reader.getSizeY(); bpp = FormatTools.getBytesPerPixel(reader.getPixelType()); planeSize = sizeY * sizeY * bpp; } finally { reader.close(); } reader = new FakeReader(); // No setId ! }
/** Copies the current dimensional position into the given array. */ private void getPosition(IFormatReader r, int no, int[] pos) { final int sizeX = r.getSizeX(); final int sizeY = r.getSizeY(); final int sizeZ = r.getSizeZ(); final int sizeT = r.getSizeT(); // final String[] cDimTypes = r.getChannelDimTypes(); final int[] cDimLengths = r.getChannelDimLengths(); final String dimOrder = r.getDimensionOrder(); final int[] zct = r.getZCTCoords(no); int index = 0; for (int i = 0; i < dimOrder.length(); i++) { final char dim = dimOrder.charAt(i); switch (dim) { case 'X': if (sizeX > 1) index++; // NB: Leave X axis position alone. break; case 'Y': if (sizeY > 1) index++; // NB: Leave Y axis position alone. break; case 'Z': if (sizeZ > 1) pos[index++] = zct[0]; break; case 'T': if (sizeT > 1) pos[index++] = zct[2]; break; case 'C': final int[] cPos = FormatTools.rasterToPosition(cDimLengths, zct[1]); for (int c = 0; c < cDimLengths.length; c++) { if (cDimLengths[c] > 1) pos[index++] = cPos[c]; } break; } } }
public static double[] readImageInfo(String id) { try { reader.setId(id); } catch (FormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // ORDERING: 0 little, 1 seriesCount, 2 pixelType, 3 bpp, 4 itkComponentType, 5 sizeX, // 6 sizeY, 7 sizeZ, 8 sizeT, 9 sizeC, 10 effSizeC, 11 rgbChannelCount, 12 imageCount // 13 physX, 14 physY, 15 physZ, 16 timeIncrement double[] returnValues = new double[17]; // return this and use SetByteOrderToLittleEndian or SetByteOrderToBigEndian in C++ land boolean little = reader.isLittleEndian(); if (little) { returnValues[0] = 1; } else { returnValues[0] = 0; } returnValues[1] = reader.getSeriesCount(); // return bpp and set an IOComponent based on it int pixelType = reader.getPixelType(); returnValues[2] = (double) pixelType; returnValues[3] = (double) FormatTools.getBytesPerPixel((int) returnValues[2]); // 0 UCHAR, 1 CHAR, 2 USHORT, 3 SHORT, 4 UINT, 5 INT, 6 FLOAT, 7 DOUBLE, 8 UNKNOWN if (pixelType == FormatTools.UINT8) returnValues[4] = (double) 0; else if (pixelType == FormatTools.INT8) returnValues[4] = (double) 1; else if (pixelType == FormatTools.UINT16) returnValues[4] = (double) 2; else if (pixelType == FormatTools.INT16) returnValues[4] = (double) 3; else if (pixelType == FormatTools.UINT32) returnValues[4] = (double) 4; else if (pixelType == FormatTools.INT32) returnValues[4] = (double) 5; else if (pixelType == FormatTools.FLOAT) returnValues[4] = (double) 6; else if (pixelType == FormatTools.DOUBLE) returnValues[4] = (double) 7; else returnValues[4] = (double) 8; // return these returnValues[5] = (double) reader.getSizeX(); returnValues[6] = (double) reader.getSizeY(); returnValues[7] = (double) reader.getSizeZ(); returnValues[8] = (double) reader.getSizeT(); returnValues[9] = (double) reader.getSizeC(); returnValues[10] = (double) reader.getEffectiveSizeC(); returnValues[11] = (double) reader.getRGBChannelCount(); returnValues[12] = (double) reader.getImageCount(); MetadataRetrieve retrieve = MetadataTools.asRetrieve(reader.getMetadataStore()); Double d = retrieve.getPixelsPhysicalSizeX(0).getValue(); double d2 = d == null ? 1.0 : d.doubleValue(); returnValues[13] = d2; d = retrieve.getPixelsPhysicalSizeY(0).getValue(); d2 = d == null ? 1.0 : d.doubleValue(); returnValues[14] = d2; d = retrieve.getPixelsPhysicalSizeZ(0).getValue(); d2 = d == null ? 1.0 : d.doubleValue(); returnValues[15] = d2; d = retrieve.getPixelsTimeIncrement(0); d2 = d == null ? 1.0 : d.doubleValue(); returnValues[16] = d2; return returnValues; }
/** * 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); } } } } } }