use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class ImageConverter method convertTilePlane.
/**
* Convert the specified plane as a set of tiles, using the specified writer.
* @param writer the {@link loci.formats.IFormatWriter} to use for writing the plane
* @param index the index of the plane to convert in the input file
* @param outputIndex the index of the plane to convert in the output file
* @param currentFile the file name or pattern being written to
* @return the time at which conversion started, in milliseconds
* @throws FormatException
* @throws IOException
*/
private long convertTilePlane(IFormatWriter writer, int index, int outputIndex, String currentFile) throws FormatException, IOException {
int w = reader.getOptimalTileWidth();
int h = reader.getOptimalTileHeight();
if (saveTileWidth > 0 && saveTileWidth <= width) {
w = saveTileWidth;
}
if (saveTileHeight > 0 && saveTileHeight <= height) {
h = saveTileHeight;
}
if (firstTile) {
LOGGER.info("Tile size = {} x {}", w, h);
firstTile = false;
}
int nXTiles = width / w;
int nYTiles = height / h;
if (nXTiles * w != width) {
nXTiles++;
}
if (nYTiles * h != height) {
nYTiles++;
}
IFD ifd = new IFD();
ifd.put(IFD.TILE_WIDTH, w);
ifd.put(IFD.TILE_LENGTH, h);
Long m = null;
for (int y = 0; y < nYTiles; y++) {
for (int x = 0; x < nXTiles; x++) {
int tileX = xCoordinate + x * w;
int tileY = yCoordinate + y * h;
int tileWidth = x < nXTiles - 1 ? w : width - (w * x);
int tileHeight = y < nYTiles - 1 ? h : height - (h * y);
byte[] buf = reader.openBytes(index, tileX, tileY, tileWidth, tileHeight);
String tileName = FormatTools.getTileFilename(x, y, y * nXTiles + x, currentFile);
if (!currentFile.equals(tileName)) {
int nTileRows = getTileRows(currentFile);
int nTileCols = getTileColumns(currentFile);
int sizeX = nTileCols == 1 ? width : tileWidth;
int sizeY = nTileRows == 1 ? height : tileHeight;
MetadataRetrieve retrieve = writer.getMetadataRetrieve();
if (retrieve instanceof MetadataStore) {
((MetadataStore) retrieve).setPixelsSizeX(new PositiveInteger(sizeX), reader.getSeries());
((MetadataStore) retrieve).setPixelsSizeY(new PositiveInteger(sizeY), reader.getSeries());
}
writer.close();
writer.setMetadataRetrieve(retrieve);
writer.setId(tileName);
if (compression != null)
writer.setCompression(compression);
outputIndex = 0;
if (nextOutputIndex.containsKey(tileName)) {
outputIndex = nextOutputIndex.get(tileName);
}
nextOutputIndex.put(tileName, outputIndex + 1);
if (nTileRows > 1) {
tileY = 0;
}
if (nTileCols > 1) {
tileX = 0;
}
}
autoscalePlane(buf, index);
applyLUT(writer);
if (m == null) {
m = System.currentTimeMillis();
}
if (writer instanceof TiffWriter) {
((TiffWriter) writer).saveBytes(outputIndex, buf, ifd, tileX, tileY, tileWidth, tileHeight);
} else if (writer instanceof ImageWriter) {
IFormatWriter baseWriter = ((ImageWriter) writer).getWriter(out);
if (baseWriter instanceof TiffWriter) {
((TiffWriter) baseWriter).saveBytes(outputIndex, buf, ifd, tileX, tileY, tileWidth, tileHeight);
}
}
}
}
return m;
}
use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class ImageInfo method printOMEXML.
public void printOMEXML() throws MissingLibraryException, ServiceException {
LOGGER.info("");
MetadataStore ms = reader.getMetadataStore();
if (baseReader instanceof ImageReader) {
baseReader = ((ImageReader) baseReader).getReader();
}
OMEXMLService service;
try {
ServiceFactory factory = new ServiceFactory();
service = factory.getInstance(OMEXMLService.class);
} catch (DependencyException de) {
throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de);
}
String version = service.getOMEXMLVersion(ms);
if (version == null)
LOGGER.info("Generating OME-XML");
else {
LOGGER.info("Generating OME-XML (schema version {})", version);
}
if (ms instanceof MetadataRetrieve) {
if (omexmlOnly) {
DebugTools.setRootLevel("INFO");
}
String xml = service.getOMEXML((MetadataRetrieve) ms);
LOGGER.info("{}", XMLTools.indentXML(xml, xmlSpaces, true));
if (omexmlOnly) {
DebugTools.setRootLevel("OFF");
}
} else {
LOGGER.info("The metadata could not be converted to OME-XML.");
if (omexmlVersion == null) {
LOGGER.info("The OME-XML Java library is probably not available.");
} else {
LOGGER.info("{} is probably not a legal schema version.", omexmlVersion);
}
}
}
use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class FormatTools method convert.
/**
* Convenience method for writing all of the images and metadata obtained
* from the specified IFormatReader into the specified IFormatWriter.
*
* It is required that setId(String) be called on the IFormatReader
* object before it is passed to convert(...). setMetadataStore(...)
* should also have been called with an appropriate instance of IMetadata.
*
* The setId(String) method must not be called on the IFormatWriter
* object; this is taken care of internally. Additionally, the
* setMetadataRetrieve(...) method in IFormatWriter should not be called.
*
* @param input the pre-initialized IFormatReader used for reading data.
* @param output the uninitialized IFormatWriter used for writing data.
* @param outputFile the full path name of the output file to be created.
* @throws FormatException if there is a general problem reading from or
* writing to one of the files.
* @throws IOException if there is an I/O-related error.
*/
public static void convert(IFormatReader input, IFormatWriter output, String outputFile) throws FormatException, IOException {
MetadataStore store = input.getMetadataStore();
MetadataRetrieve meta = null;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
meta = service.asRetrieve(store);
} catch (DependencyException de) {
throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de);
}
output.setMetadataRetrieve(meta);
output.setId(outputFile);
for (int series = 0; series < input.getSeriesCount(); series++) {
input.setSeries(series);
output.setSeries(series);
byte[] buf = new byte[getPlaneSize(input)];
for (int image = 0; image < input.getImageCount(); image++) {
input.openBytes(image, buf);
output.saveBytes(image, buf);
}
}
input.close();
output.close();
}
use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class LociFunctions method getPixelsPhysicalSizeX.
public void getPixelsPhysicalSizeX(Double[] sizeX) {
int imageIndex = r.getSeries();
MetadataRetrieve retrieve = (MetadataRetrieve) r.getMetadataStore();
Length x = retrieve.getPixelsPhysicalSizeX(imageIndex);
if (x != null) {
sizeX[0] = x.value(UNITS.MICROMETER).doubleValue();
}
if (sizeX[0] == null)
sizeX[0] = new Double(Double.NaN);
}
use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class LociFunctions method getPixelsTimeIncrement.
public void getPixelsTimeIncrement(Double[] sizeT) {
int imageIndex = r.getSeries();
MetadataRetrieve retrieve = (MetadataRetrieve) r.getMetadataStore();
sizeT[0] = retrieve.getPixelsTimeIncrement(imageIndex).value(UNITS.SECOND).doubleValue();
if (sizeT[0] == null)
sizeT[0] = new Double(Double.NaN);
}
Aggregations