use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class SubResolutionExample method main.
public static void main(String[] args) throws FormatException, IOException {
// parse command line arguments
if (args.length < 1) {
System.err.println("Usage: java SubResolutionExample imageFile");
System.exit(1);
}
String id = args[0];
// configure reader
IFormatReader reader = new ImageReader();
reader.setFlattenedResolutions(false);
System.out.println("Initializing file: " + id);
// parse metadata
reader.setId(id);
int seriesCount = reader.getSeriesCount();
System.out.println(" Series count = " + seriesCount);
for (int series = 0; series < seriesCount; series++) {
reader.setSeries(series);
int resolutionCount = reader.getResolutionCount();
System.out.println(" Resolution count for series #" + series + " = " + resolutionCount);
for (int r = 0; r < resolutionCount; r++) {
reader.setResolution(r);
System.out.println(" Resolution #" + r + " dimensions = " + reader.getSizeX() + " x " + reader.getSizeY());
}
}
reader.close();
}
use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class TiledExportExample method main.
public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.out.println("Usage: java TiledExportExample <infile> <outfile>");
System.exit(1);
}
ImageReader reader = new ImageReader();
ImageWriter writer = new ImageWriter();
IMetadata meta;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
meta = service.createOMEXMLMetadata();
} catch (DependencyException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
} catch (ServiceException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
}
reader.setMetadataStore(meta);
reader.setId(args[0]);
writer.setMetadataRetrieve(meta);
writer.setId(args[1]);
for (int series = 0; series < reader.getSeriesCount(); series++) {
reader.setSeries(series);
writer.setSeries(series);
for (int image = 0; image < reader.getImageCount(); image++) {
for (int row = 0; row < 2; row++) {
for (int col = 0; col < 2; col++) {
int w = reader.getSizeX() / 2;
int h = reader.getSizeY() / 2;
int x = col * w;
int y = row * h;
/* debug */
System.out.println("[" + x + ", " + y + ", " + w + ", " + h + "]");
byte[] buf = reader.openBytes(image, x, y, w, h);
writer.saveBytes(image, buf, x, y, w, h);
}
}
}
}
reader.close();
writer.close();
}
use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class OrthogonalReader method readOrthogonalPlanes.
private void readOrthogonalPlanes() throws Exception {
// Setup logger
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
if (debug) {
root.setLevel(Level.DEBUG);
} else {
root.setLevel(Level.INFO);
}
ImageReader reader = this.initialiseReader(this.input);
reader.setSeries(0);
OMETiffWriter writer = this.initialiseWriter(this.output, reader);
int index;
// Write XZ planes
writer.setSeries(0);
for (int y = 0; y < reader.getSizeY(); y++) {
ByteBuffer bufferXZ = ByteBuffer.allocate((int) (0.125 * reader.getBitsPerPixel()) * reader.getSizeX() * reader.getSizeZ());
for (int z = 0; z < reader.getSizeZ(); z++) {
index = reader.getIndex(z, 0, 0);
byte[] line = reader.openBytes(index, 0, y, reader.getSizeX(), 1);
bufferXZ.put(line);
}
log.debug("y: {}, {}", y, bufferXZ.array().length);
writer.saveBytes(y, bufferXZ.array());
}
// Write YZ planes
writer.setSeries(1);
for (int x = 0; x < reader.getSizeX(); x++) {
ByteBuffer bufferYZ = ByteBuffer.allocate((int) (0.125 * reader.getBitsPerPixel()) * reader.getSizeY() * reader.getSizeZ());
for (int z = 0; z < reader.getSizeZ(); z++) {
index = reader.getIndex(z, 0, 0);
byte[] line = reader.openBytes(index, x, 0, 1, reader.getSizeY());
bufferYZ.put(line);
}
log.debug("x: {}, {}", x, bufferYZ.array().length);
writer.saveBytes(x, bufferYZ.array());
}
reader.close();
writer.close();
}
use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class OrthogonalReader method initialiseReader.
private ImageReader initialiseReader(String fileName) throws Exception {
ImageReader reader = new ImageReader();
reader.setId(fileName);
return reader;
}
use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class ReadPhysicalSize method readPhysicalSize.
/**
* Reads the physical dimensions of the input file provided then converts and displays them in micrometers
*
* @param inputFile the file to be read
* @throws FormatException if a parsing error occurs processing the file.
* @throws IOException if an I/O error occurs processing the file
*/
public static void readPhysicalSize(final String inputFile) throws FormatException, IOException {
final ImageReader reader = new ImageReader();
final IMetadata omeMeta = MetadataTools.createOMEXMLMetadata();
reader.setMetadataStore(omeMeta);
reader.setId(inputFile);
final Unit<Length> targetUnit = UNITS.MICROMETER;
for (int image = 0; image < omeMeta.getImageCount(); image++) {
final Length physSizeX = omeMeta.getPixelsPhysicalSizeX(image);
final Length physSizeY = omeMeta.getPixelsPhysicalSizeY(image);
final Length physSizeZ = omeMeta.getPixelsPhysicalSizeZ(image);
System.out.println("Physical calibration - Image: " + image);
if (physSizeX != null) {
final Length convertedSizeX = new Length(physSizeX.value(targetUnit), targetUnit);
System.out.println("\tX = " + physSizeX.value() + " " + physSizeX.unit().getSymbol() + " = " + convertedSizeX.value() + " " + convertedSizeX.unit().getSymbol());
}
if (physSizeY != null) {
final Length convertedSizeY = new Length(physSizeY.value(targetUnit), targetUnit);
System.out.println("\tY = " + physSizeY.value() + " " + physSizeY.unit().getSymbol() + " = " + convertedSizeY.value() + " " + convertedSizeY.unit().getSymbol());
}
if (physSizeZ != null) {
final Length convertedSizeZ = new Length(physSizeZ.value(targetUnit), targetUnit);
System.out.println("\tZ = " + physSizeZ.value() + " " + physSizeZ.unit().getSymbol() + " = " + convertedSizeZ.value() + " " + convertedSizeZ.unit().getSymbol());
}
}
reader.close();
}
Aggregations