use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class BaseModelNoBinDataReaderTest method testSetId.
@Test
public void testSetId() throws Exception {
reader = new MinMaxCalculator(new ChannelSeparator(new ChannelFiller(new ImageReader())));
metadata = new OMEXMLMetadataImpl();
reader.setMetadataStore(metadata);
reader.setId(temporaryFile.getAbsolutePath());
}
use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class EightBitLosslessJPEG2000Test method testLosslessPixels.
@Test
public void testLosslessPixels() throws Exception {
int failureCount = 0;
for (int i = 0; i < files.size(); i++) {
ImageReader reader = new ImageReader();
reader.setId(files.get(i));
byte[] plane = reader.openBytes(0);
if (plane[0] != pixels[i][0]) {
LOGGER.debug("FAILED on {}", pixels[i][0]);
failureCount++;
}
reader.close();
}
assertEquals(failureCount, 0);
}
use of loci.formats.ImageReader in project digilib by robcast.
the class BioFormatsDocuImage method identify.
/*
* (non-Javadoc)
*
* @see digilib.image.DocuImageImpl#identify(digilib.io.ImageInput)
*/
@Override
public ImageInput identify(ImageInput ii) throws IOException {
ImageReader reader = new ImageReader();
try {
reader.setId(ii.getFile().getAbsolutePath());
} catch (FormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int width = reader.getSizeX();
int height = reader.getSizeY();
String fmt = reader.getFormat();
String mt = "";
if (fmt.equalsIgnoreCase("Tagged Image File Format")) {
mt = "image/tiff";
} else if (fmt.equalsIgnoreCase("JPEG")) {
mt = "image/jpeg";
}
logger.debug("BioFormats identify: width=" + width + " height=" + height + " format=" + fmt + " mimetype=" + mt);
ii.setSize(new ImageSize(width, height));
ii.setMimetype(mt);
return ii;
}
use of loci.formats.ImageReader 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.ImageReader in project bioformats by openmicroscopy.
the class ImageInfo method testRead.
/**
* A utility method for reading a file from the command line,
* and displaying the results in a simple display.
*/
public boolean testRead(String[] args) throws FormatException, ServiceException, IOException {
for (final String arg : args) {
if (HELP_ARGUMENTS.contains(arg)) {
if (reader == null) {
reader = new ImageReader();
}
printUsage();
return false;
}
}
boolean validArgs = parseArgs(args);
if (!validArgs)
return false;
if (printVersion) {
CommandLineTools.printVersion();
return true;
}
CommandLineTools.runUpgradeCheck(args);
createReader();
if (id == null) {
printUsage();
return false;
}
mapLocation();
configureReaderPreInit();
// initialize reader
long s = System.currentTimeMillis();
try {
reader.setId(id);
} catch (FormatException exc) {
reader.close();
LOGGER.error("Failure during the reader initialization");
LOGGER.debug("", exc);
return false;
}
long e = System.currentTimeMillis();
float sec = (e - s) / 1000f;
LOGGER.info("Initialization took {}s", sec);
configureReaderPostInit();
checkWarnings();
readCoreMetadata();
reader.setSeries(series);
if (flat == false)
reader.setResolution(resolution);
initPreMinMaxValues();
// read pixels
if (pixels)
readPixels();
// read format-specific metadata table
if (doMeta) {
printGlobalMetadata();
printOriginalMetadata();
}
// output OME-XML
if (omexml)
printOMEXML();
if (!pixels) {
reader.close();
}
return true;
}
Aggregations