use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class ImageInfo method readCoreMetadata.
public void readCoreMetadata() throws FormatException, IOException {
// skip core metadata printout
if (!doCore)
return;
// read basic metadata
LOGGER.info("");
LOGGER.info("Reading core metadata");
LOGGER.info("{} = {}", stitch ? "File pattern" : "filename", stitch ? id : reader.getCurrentFile());
if (map != null)
LOGGER.info("Mapped filename = {}", map);
if (usedFiles) {
String[] used = reader.getUsedFiles();
boolean usedValid = used != null && used.length > 0;
if (usedValid) {
for (int u = 0; u < used.length; u++) {
if (used[u] == null) {
usedValid = false;
break;
}
}
}
if (!usedValid) {
LOGGER.warn("************ invalid used files list ************");
}
if (used == null) {
LOGGER.info("Used files = null");
} else if (used.length == 0) {
LOGGER.info("Used files = []");
} else if (used.length > 1) {
LOGGER.info("Used files:");
for (int u = 0; u < used.length; u++) LOGGER.info("\t{}", used[u]);
} else if (!id.equals(used[0])) {
LOGGER.info("Used files = [{}]", used[0]);
}
}
int seriesCount = reader.getSeriesCount();
LOGGER.info("Series count = {}", seriesCount);
MetadataStore ms = reader.getMetadataStore();
MetadataRetrieve mr = ms instanceof MetadataRetrieve ? (MetadataRetrieve) ms : null;
for (int j = 0; j < seriesCount; j++) {
reader.setSeries(j);
// read basic metadata for series #i
int imageCount = reader.getImageCount();
int resolutions = reader.getResolutionCount();
boolean rgb = reader.isRGB();
int sizeX = reader.getSizeX();
int sizeY = reader.getSizeY();
int sizeZ = reader.getSizeZ();
int sizeC = reader.getSizeC();
int sizeT = reader.getSizeT();
int pixelType = reader.getPixelType();
int validBits = reader.getBitsPerPixel();
int effSizeC = reader.getEffectiveSizeC();
int rgbChanCount = reader.getRGBChannelCount();
boolean indexed = reader.isIndexed();
boolean falseColor = reader.isFalseColor();
byte[][] table8 = reader.get8BitLookupTable();
short[][] table16 = reader.get16BitLookupTable();
Modulo moduloZ = reader.getModuloZ();
Modulo moduloC = reader.getModuloC();
Modulo moduloT = reader.getModuloT();
int thumbSizeX = reader.getThumbSizeX();
int thumbSizeY = reader.getThumbSizeY();
int tileSizeX = reader.getOptimalTileWidth();
int tileSizeY = reader.getOptimalTileHeight();
boolean little = reader.isLittleEndian();
String dimOrder = reader.getDimensionOrder();
boolean orderCertain = reader.isOrderCertain();
boolean thumbnail = reader.isThumbnailSeries();
boolean interleaved = reader.isInterleaved();
boolean metadataComplete = reader.isMetadataComplete();
// output basic metadata for series #i
String seriesName = mr == null ? null : mr.getImageName(j);
LOGGER.info("Series #{}{}{}:", new Object[] { j, seriesName == null ? " " : " -- ", seriesName == null ? "" : seriesName });
if (flat == false && resolutions > 1) {
LOGGER.info("\tResolutions = {}", resolutions);
for (int i = 0; i < resolutions; i++) {
reader.setResolution(i);
LOGGER.info("\t\tsizeX[{}] = {}", i, reader.getSizeX());
}
reader.setResolution(0);
}
LOGGER.info("\tImage count = {}", imageCount);
LOGGER.info("\tRGB = {} ({}) {}", new Object[] { rgb, rgbChanCount, merge ? "(merged)" : separate ? "(separated)" : "" });
if (rgb != (rgbChanCount != 1)) {
LOGGER.warn("\t************ RGB mismatch ************");
}
LOGGER.info("\tInterleaved = {}", interleaved);
StringBuilder sb = new StringBuilder();
sb.append("\tIndexed = ");
sb.append(indexed);
sb.append(" (");
sb.append(!falseColor);
sb.append(" color");
if (table8 != null) {
sb.append(", 8-bit LUT: ");
sb.append(table8.length);
sb.append(" x ");
sb.append(table8[0] == null ? "null" : "" + table8[0].length);
}
if (table16 != null) {
sb.append(", 16-bit LUT: ");
sb.append(table16.length);
sb.append(" x ");
sb.append(table16[0] == null ? "null" : "" + table16[0].length);
}
sb.append(")");
LOGGER.info(sb.toString());
if (table8 != null && table16 != null) {
LOGGER.warn("\t************ multiple LUTs ************");
}
LOGGER.info("\tWidth = {}", sizeX);
LOGGER.info("\tHeight = {}", sizeY);
printDimension("SizeZ", sizeZ, sizeZ, moduloZ);
printDimension("SizeT", sizeT, sizeT, moduloT);
printDimension("SizeC", sizeC, effSizeC, moduloC);
if (imageCount != sizeZ * effSizeC * sizeT) {
LOGGER.info("\t************ ZCT mismatch ************");
}
LOGGER.info("\tTile size = {} x {}", tileSizeX, tileSizeY);
LOGGER.info("\tThumbnail size = {} x {}", thumbSizeX, thumbSizeY);
LOGGER.info("\tEndianness = {}", little ? "intel (little)" : "motorola (big)");
LOGGER.info("\tDimension order = {} ({})", dimOrder, orderCertain ? "certain" : "uncertain");
LOGGER.info("\tPixel type = {}", FormatTools.getPixelTypeString(pixelType));
LOGGER.info("\tValid bits per pixel = {}", validBits);
LOGGER.info("\tMetadata complete = {}", metadataComplete);
LOGGER.info("\tThumbnail series = {}", thumbnail);
if (doMeta) {
LOGGER.info("\t-----");
int[] indices;
if (imageCount > 6) {
int q = imageCount / 2;
indices = new int[] { 0, q - 2, q - 1, q, q + 1, q + 2, imageCount - 1 };
} else if (imageCount > 2) {
indices = new int[] { 0, imageCount / 2, imageCount - 1 };
} else if (imageCount > 1)
indices = new int[] { 0, 1 };
else
indices = new int[] { 0 };
int[][] zct = new int[indices.length][];
int[] indices2 = new int[indices.length];
sb.setLength(0);
for (int i = 0; i < indices.length; i++) {
zct[i] = reader.getZCTCoords(indices[i]);
indices2[i] = reader.getIndex(zct[i][0], zct[i][1], zct[i][2]);
sb.append("\tPlane #");
sb.append(indices[i]);
sb.append(" <=> Z ");
sb.append(zct[i][0]);
sb.append(", C ");
sb.append(zct[i][1]);
sb.append(", T ");
sb.append(zct[i][2]);
if (indices[i] != indices2[i]) {
sb.append(" [mismatch: ");
sb.append(indices2[i]);
sb.append("]");
sb.append(NEWLINE);
} else
sb.append(NEWLINE);
}
LOGGER.info(sb.toString());
}
}
}
use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class FormatTools method getFilename.
/**
* @throws FormatException Never actually thrown.
* @throws IOException Never actually thrown.
*/
public static String getFilename(int series, int image, IFormatReader r, String pattern, boolean padded) throws FormatException, IOException {
MetadataStore store = r.getMetadataStore();
MetadataRetrieve retrieve = store instanceof MetadataRetrieve ? (MetadataRetrieve) store : new DummyMetadata();
return getFilename(series, image, retrieve, pattern, padded);
}
use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class FormatWriter method setId.
// -- IFormatHandler API methods --
/**
* Initializes a writer from the input file name.
*
* Initializes a {@link RandomAccessOutputStream} for the output
* file and initializes the metadata for all the series using
* {@link #setSeries(int)}.
*
* @param id a {@link String} specifying the path to the file
*/
@Override
public void setId(String id) throws FormatException, IOException {
if (id.equals(currentId))
return;
currentId = id;
if (out != null) {
out.close();
}
out = createOutputStream();
MetadataRetrieve r = getMetadataRetrieve();
initialized = new boolean[r.getImageCount()][];
for (int i = 0; i < r.getImageCount(); i++) {
initialized[i] = new boolean[getPlaneCount(i)];
}
}
use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class FormatWriter method checkParams.
// -- Helper methods --
/**
* Ensure that the arguments that are being passed to saveBytes(...) are
* valid.
* @throws FormatException if any of the arguments is invalid.
*/
protected void checkParams(int no, byte[] buf, int x, int y, int w, int h) throws FormatException {
MetadataRetrieve r = getMetadataRetrieve();
MetadataTools.verifyMinimumPopulated(r, series);
if (buf == null)
throw new FormatException("Buffer cannot be null.");
int z = r.getPixelsSizeZ(series).getValue().intValue();
int t = r.getPixelsSizeT(series).getValue().intValue();
int c = r.getChannelCount(series);
int planes = z * c * t;
if (no < 0)
throw new FormatException(String.format("Plane index:%d must be >= 0", no));
if (no >= planes) {
throw new FormatException(String.format("Plane index:%d must be < %d", no, planes));
}
int sizeX = r.getPixelsSizeX(series).getValue().intValue();
int sizeY = r.getPixelsSizeY(series).getValue().intValue();
if (x < 0)
throw new FormatException(String.format("X:%d must be >= 0", x));
if (y < 0)
throw new FormatException(String.format("Y:%d must be >= 0", y));
if (x >= sizeX) {
throw new FormatException(String.format("X:%d must be < %d", x, sizeX));
}
if (y >= sizeY) {
throw new FormatException(String.format("Y:%d must be < %d", y, sizeY));
}
if (w <= 0)
throw new FormatException(String.format("Width:%d must be > 0", w));
if (h <= 0)
throw new FormatException(String.format("Height:%d must be > 0", h));
if (x + w > sizeX)
throw new FormatException(String.format("(w:%d + x:%d) must be <= %d", w, x, sizeX));
if (y + h > sizeY)
throw new FormatException(String.format("(h:%d + y:%d) must be <= %d", h, y, sizeY));
int pixelType = FormatTools.pixelTypeFromString(r.getPixelsType(series).toString());
int bpp = FormatTools.getBytesPerPixel(pixelType);
PositiveInteger samples = r.getChannelSamplesPerPixel(series, 0);
if (samples == null)
samples = new PositiveInteger(1);
int minSize = bpp * w * h * samples.getValue();
if (buf.length < minSize) {
throw new FormatException("Buffer is too small; expected " + minSize + " bytes, got " + buf.length + " bytes.");
}
if (!DataTools.containsValue(getPixelTypes(compression), pixelType)) {
throw new FormatException("Unsupported image type '" + FormatTools.getPixelTypeString(pixelType) + "'.");
}
}
use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class FormatWriter method isFullPlane.
/**
* Returns true if the given rectangle coordinates correspond to a full
* image in the given series.
*/
protected boolean isFullPlane(int x, int y, int w, int h) {
MetadataRetrieve r = getMetadataRetrieve();
int sizeX = r.getPixelsSizeX(series).getValue().intValue();
int sizeY = r.getPixelsSizeY(series).getValue().intValue();
return x == 0 && y == 0 && w == sizeX && h == sizeY;
}
Aggregations