use of loci.formats.IFormatReader in project bioformats by openmicroscopy.
the class FormatReaderTest method testUnflattenedPixelsHashes.
@Test(groups = { "all", "pixels", "automated" })
public void testUnflattenedPixelsHashes() {
if (config == null)
throw new SkipException("No config tree");
String testName = "testUnflattenedPixelsHashes";
if (!initFile())
result(testName, false, "initFile");
boolean success = true;
String msg = null;
try {
IFormatReader resolutionReader = new BufferedImageReader(new FileStitcher());
resolutionReader.setFlattenedResolutions(false);
resolutionReader.setNormalized(true);
resolutionReader.setOriginalMetadataPopulated(false);
resolutionReader.setMetadataFiltered(true);
resolutionReader.setId(id);
// check the MD5 of the first plane in each resolution
for (int i = 0; i < resolutionReader.getSeriesCount() && success; i++) {
resolutionReader.setSeries(i);
for (int r = 0; r < resolutionReader.getResolutionCount() && success; r++) {
resolutionReader.setResolution(r);
config.setSeries(resolutionReader.getCoreIndex());
long planeSize = -1;
try {
planeSize = DataTools.safeMultiply32(resolutionReader.getSizeX(), resolutionReader.getSizeY(), resolutionReader.getRGBChannelCount(), FormatTools.getBytesPerPixel(resolutionReader.getPixelType()));
} catch (IllegalArgumentException e) {
continue;
}
if (planeSize < 0 || !TestTools.canFitInMemory(planeSize)) {
continue;
}
String md5 = TestTools.md5(resolutionReader.openBytes(0));
String expected1 = config.getMD5();
String expected2 = config.getAlternateMD5();
if (expected1 == null && expected2 == null) {
continue;
}
if (!md5.equals(expected1) && !md5.equals(expected2)) {
success = false;
msg = "series " + i + ", resolution " + r;
}
}
}
resolutionReader.close();
} catch (Throwable t) {
if (TestTools.isOutOfMemory(t)) {
result(testName, true, "Image too large");
return;
}
LOGGER.info("", t);
success = false;
}
result(testName, success, msg);
}
use of loci.formats.IFormatReader 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.IFormatReader in project TrakEM2 by trakem2.
the class Loader method getDimensions.
/**
* Read out the width,height of an image using LOCI BioFormats.
*/
public static Dimension getDimensions(final String path) {
IFormatReader fr = null;
try {
fr = new ChannelSeparator();
fr.setGroupFiles(false);
fr.setId(path);
return new Dimension(fr.getSizeX(), fr.getSizeY());
} catch (final FormatException fe) {
Utils.log("Error in reading image file at " + path + "\n" + fe);
} catch (final Exception e) {
IJError.print(e);
} finally {
if (null != fr)
try {
fr.close();
} catch (final IOException ioe) {
Utils.log2("Could not close IFormatReader: " + ioe);
}
}
return null;
}
Aggregations