use of loci.formats.gui.BufferedImageReader in project bioformats by openmicroscopy.
the class SeriesDialog method constructDialog.
@Override
protected GenericDialog constructDialog() {
final int seriesCount = process.getSeriesCount();
// NB: Load thumbnails only when series count is modest.
if (seriesCount < MAX_SERIES_THUMBS) {
// construct thumbnail reader
thumbReader = new BufferedImageReader(process.getReader());
// set up the thumbnail panels
p = new Panel[seriesCount];
for (int i = 0; i < seriesCount; i++) {
thumbReader.setSeries(i);
// a little extra padding
int sx = thumbReader.getThumbSizeX() + 10;
int sy = thumbReader.getThumbSizeY();
p[i] = new Panel();
p[i].add(Box.createRigidArea(new Dimension(sx, sy)));
if (options.isForceThumbnails()) {
// load thumbnail immediately
ThumbLoader.loadThumb(thumbReader, i, p[i], options.isQuiet());
}
}
}
GenericDialog gd = new GenericDialog("Bio-Formats Series Options");
// NB: Provide individual checkboxes only when series count is manageable.
if (seriesCount < MAX_SERIES_TOGGLES) {
// NB: We need to add the checkboxes in groups, to prevent an
// exception from being thrown if there are more than 512 series.
// See also:
// http://dev.loci.wisc.edu/trac/java/ticket/408 and
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5107980
final int nGroups = (seriesCount + MAX_COMPONENTS - 1) / MAX_COMPONENTS;
int nextSeries = 0;
for (int i = 0; i < nGroups; i++) {
final int nRows = Math.min(MAX_COMPONENTS, seriesCount - nextSeries);
final String[] labels = new String[nRows];
final boolean[] defaultValues = new boolean[nRows];
for (int row = 0; row < nRows; row++) {
labels[row] = process.getSeriesLabel(nextSeries);
defaultValues[row] = options.isSeriesOn(nextSeries);
nextSeries++;
}
gd.addCheckboxGroup(nRows, 1, labels, defaultValues);
}
// extract checkboxes, for "Select All" and "Deselect All" functions
boxes = WindowTools.getCheckboxes(gd).toArray(new Checkbox[0]);
// rebuild dialog so that the thumbnails and checkboxes line up correctly
rebuildDialog(gd, nGroups);
} else {
// too many series; display a simple text field for specifying series
gd.addMessage("Please specify the image series you wish to import.\n" + "Use commas to list multiple series. You can also use\n" + "a dash to represent a range of series. For example,\n" + "to import series 1, 3, 4, 5, 7, 8, 9, 12, 15 & 16,\n" + "you could write: 1, 3-5, 7-9, 12, 15-16\n \n" + "There are " + seriesCount + " total series.");
gd.addStringField("Series_list: ", "1");
}
return gd;
}
use of loci.formats.gui.BufferedImageReader in project bioformats by openmicroscopy.
the class FormatReaderTest method setupReader.
// -- Helper methods --
/**
* Sets up the current IFormatReader.
*/
private void setupReader() {
// Remove external SlideBook6Reader class for testing purposes
ImageReader ir = new ImageReader();
reader = new BufferedImageReader(new FileStitcher(new Memoizer(ir, Memoizer.DEFAULT_MINIMUM_ELAPSED, new File(""))));
reader.setMetadataOptions(new DefaultMetadataOptions(MetadataLevel.NO_OVERLAYS));
reader.setNormalized(true);
reader.setOriginalMetadataPopulated(false);
reader.setMetadataFiltered(true);
MetadataStore store = null;
try {
store = omexmlService.createOMEXMLMetadata();
} catch (ServiceException e) {
LOGGER.warn("Could not parse OME-XML", e);
}
reader.setMetadataStore(store);
}
use of loci.formats.gui.BufferedImageReader in project bioformats by openmicroscopy.
the class ImageInfo method configureReaderPreInit.
public void configureReaderPreInit() throws FormatException, IOException {
if (omexml) {
reader.setOriginalMetadataPopulated(originalMetadata);
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
reader.setMetadataStore(service.createOMEXMLMetadata(null, omexmlVersion));
} catch (DependencyException de) {
throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de);
} catch (ServiceException se) {
throw new FormatException(se);
}
}
// check file format
if (reader instanceof ImageReader) {
// determine format
ImageReader ir = (ImageReader) reader;
if (new Location(id).exists()) {
LOGGER.info("Checking file format [{}]", ir.getFormat(id));
}
} else {
// verify format
LOGGER.info("Checking {} format [{}]", reader.getFormat(), reader.isThisType(id) ? "yes" : "no");
}
LOGGER.info("Initializing reader");
if (stitch) {
reader = new FileStitcher(reader, true);
Location f = new Location(id);
String pat = null;
if (!f.exists()) {
((FileStitcher) reader).setUsingPatternIds(true);
pat = id;
} else {
pat = FilePattern.findPattern(f);
}
if (pat != null)
id = pat;
}
if (expand)
reader = new ChannelFiller(reader);
if (separate)
reader = new ChannelSeparator(reader);
if (merge)
reader = new ChannelMerger(reader);
if (cache) {
if (cachedir != null) {
reader = new Memoizer(reader, 0, new File(cachedir));
} else {
reader = new Memoizer(reader, 0);
}
}
minMaxCalc = null;
if (minmax || autoscale)
reader = minMaxCalc = new MinMaxCalculator(reader);
dimSwapper = null;
if (swapOrder != null || shuffleOrder != null) {
reader = dimSwapper = new DimensionSwapper(reader);
}
reader = biReader = new BufferedImageReader(reader);
reader.close();
reader.setNormalized(normalize);
reader.setMetadataFiltered(filter);
reader.setGroupFiles(group);
options.setMetadataLevel(doMeta ? MetadataLevel.ALL : MetadataLevel.MINIMUM);
options.setValidate(validate);
reader.setMetadataOptions(options);
reader.setFlattenedResolutions(flat);
}
use of loci.formats.gui.BufferedImageReader in project bioformats by openmicroscopy.
the class FormatReaderTest method testUnflattenedSubimagePixelsHashes.
/*
@Test(groups = {"all", "pixels"})
public void testReorderedPixelsHashes() {
if (config == null) throw new SkipException("No config tree");
String testName = "testReorderedPixelsHashes";
if (!initFile()) result(testName, false, "initFile");
boolean success = true;
String msg = null;
try {
for (int i=0; i<reader.getSeriesCount() && success; i++) {
reader.setSeries(i);
config.setSeries(i);
for (int j=0; j<3; j++) {
int index = (int) (Math.random() * reader.getImageCount());
reader.openBytes(index);
}
String md5 = TestTools.md5(reader.openBytes(0));
String expected1 = config.getMD5();
String expected2 = config.getAlternateMD5();
if (!md5.equals(expected1) && !md5.equals(expected2)) {
success = false;
msg = expected1 == null && expected2 == null ? "no configuration" :
"series " + i;
}
}
}
catch (Throwable t) {
LOGGER.info("", t);
success = false;
}
result(testName, success, msg);
}
*/
@Test(groups = { "all", "pixels", "automated" })
public void testUnflattenedSubimagePixelsHashes() {
if (config == null)
throw new SkipException("No config tree");
String testName = "testUnflattenedSubimagePixelsHashes";
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());
int w = (int) Math.min(Configuration.TILE_SIZE, resolutionReader.getSizeX());
int h = (int) Math.min(Configuration.TILE_SIZE, resolutionReader.getSizeY());
String expected1 = config.getTileMD5();
String expected2 = config.getTileAlternateMD5();
String md5 = null;
try {
md5 = TestTools.md5(resolutionReader.openBytes(0, 0, 0, w, h));
} catch (Throwable e) {
if (TestTools.isOutOfMemory(e)) {
result(testName, true, "Image too large");
return;
}
LOGGER.warn("", e);
}
if (md5 == null && expected1 == null && expected2 == null) {
success = true;
} else if (!md5.equals(expected1) && !md5.equals(expected2) && (expected1 != null || expected2 != null)) {
success = false;
msg = "series " + i + ", resolution " + r;
}
}
}
resolutionReader.close();
} catch (Throwable t) {
LOGGER.info("", t);
success = false;
}
result(testName, success, msg);
}
use of loci.formats.gui.BufferedImageReader 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);
}
Aggregations