use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class MakeDatasetStructureTable method printTable.
/**
* Write the table to the file specified using setOutputFile(String[])
*/
public void printTable() {
ImageReader baseReader = new ImageReader();
IFormatReader[] allReaders = baseReader.getReaders();
Comparator<IFormatReader> comparator = new Comparator<IFormatReader>() {
@Override
public int compare(IFormatReader r1, IFormatReader r2) {
String s1 = r1.getFormat();
String s2 = r2.getFormat();
return s1.compareTo(s2);
}
};
Arrays.sort(allReaders, comparator);
printHeader();
for (IFormatReader reader : allReaders) {
try {
printFormatEntry(reader);
} catch (IllegalStateException e) {
}
}
printFooter();
}
use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class HitachiReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
if (!checkSuffix(id, "txt")) {
String base = id;
if (base.indexOf('.') >= 0) {
base = base.substring(0, base.lastIndexOf("."));
}
id = base + ".txt";
initFile(id);
return;
}
super.initFile(id);
String data = DataTools.readFile(id);
IniParser parser = new IniParser();
parser.setBackslashContinuesLine(false);
IniList ini = parser.parseINI(new BufferedReader(new StringReader(data)));
IniTable image = ini.getTable("SemImageFile");
if (image == null) {
throw new FormatException("Could not find 'SemImageFile' table.");
}
for (String key : image.keySet()) {
addGlobalMeta(key, image.get(key));
}
String imageName = image.get("SampleName");
String pixelsFile = image.get("ImageName");
String date = image.get("Date");
String time = image.get("Time");
Location parent = new Location(id).getAbsoluteFile().getParentFile();
pixelsFile = new Location(parent, pixelsFile).getAbsolutePath();
ClassList<IFormatReader> classes = ImageReader.getDefaultReaderClasses();
Class<? extends IFormatReader>[] classArray = classes.getClasses();
ClassList<IFormatReader> newClasses = new ClassList<IFormatReader>(IFormatReader.class);
for (Class<? extends IFormatReader> c : classArray) {
if (!c.equals(HitachiReader.class)) {
newClasses.addClass(c);
}
}
helperReader = new ImageReader(newClasses);
helperReader.setId(pixelsFile);
core = new ArrayList<CoreMetadata>(helperReader.getCoreMetadataList());
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM);
store.setImageName(imageName, 0);
date = DateTools.formatDate(date + " " + time, DATE_FORMAT);
if (date != null) {
store.setImageAcquisitionDate(new Timestamp(date), 0);
}
populateOMEMetadata(image, store);
}
use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class GetPhysicalMetadata method main.
public static void main(String[] args) throws Exception {
// parse command line arguments
if (args.length < 1) {
System.err.println("Usage: java GetMetadata imageFile [seriesNo]");
System.exit(1);
}
String id = args[0];
int series = args.length > 1 ? Integer.parseInt(args[1]) : 0;
// create OME-XML metadata store
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata meta = service.createOMEXMLMetadata();
// create format reader
IFormatReader reader = new ImageReader();
reader.setMetadataStore(meta);
// initialize file
System.out.println("Initializing " + id);
reader.setId(id);
int seriesCount = reader.getSeriesCount();
if (series < seriesCount)
reader.setSeries(series);
series = reader.getSeries();
System.out.println("\tImage series = " + series + " of " + seriesCount);
printPixelDimensions(reader);
printPhysicalDimensions(meta, series);
}
use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class MultiFileExample method main.
public static void main(String[] args) throws FormatException, IOException {
if (args.length < 2) {
System.out.println("You must specify two files.");
System.exit(1);
}
ImageReader[] readers = new ImageReader[args.length];
for (int i = 0; i < readers.length; i++) {
readers[i] = new ImageReader();
readers[i].setId(args[i]);
}
// read plane #0 from file #0
readers[0].openBytes(0);
// read plane #0 from file #1
readers[1].openBytes(0);
// the other option is to use a single reader for all of the files
// this will use a little less memory, but is substantially slower
// unless you read all of the planes from one file before moving on
// to the next file
//
// if you want one reader total, uncomment the following:
/*
ImageReader reader = new ImageReader();
//read plane #0 from file #0
reader.setId(args[0]);
reader.openBytes(0);
// read plane #0 from file #1
reader.setId(args[1]);
reader.openBytes(0);
*/
}
use of loci.formats.ImageReader in project bioformats by openmicroscopy.
the class ParallelRead method run.
public void run() {
try {
ImageReader r = new ImageReader();
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata meta = service.createOMEXMLMetadata();
r.setMetadataStore(meta);
r.setId(id);
System.out.println(Thread.currentThread().getName() + ": id=" + id + ", sizeX=" + r.getSizeX() + ", sizeY=" + r.getSizeY() + ", sizeZ=" + r.getSizeZ() + ", sizeT=" + r.getSizeT() + ", sizeC=" + r.getSizeC() + ", imageName=" + meta.getImageName(0));
r.close();
} catch (Exception exc) {
exc.printStackTrace();
}
}
Aggregations