Search in sources :

Example 1 with ImageReader

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();
}
Also used : IFormatReader(loci.formats.IFormatReader) ImageReader(loci.formats.ImageReader) Comparator(java.util.Comparator)

Example 2 with ImageReader

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);
}
Also used : IniParser(loci.common.IniParser) IFormatReader(loci.formats.IFormatReader) IniList(loci.common.IniList) ClassList(loci.formats.ClassList) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) IniTable(loci.common.IniTable) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) ImageReader(loci.formats.ImageReader) Location(loci.common.Location)

Example 3 with ImageReader

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);
}
Also used : IMetadata(loci.formats.meta.IMetadata) IFormatReader(loci.formats.IFormatReader) ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) OMEXMLService(loci.formats.services.OMEXMLService)

Example 4 with ImageReader

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);
    */
}
Also used : ImageReader(loci.formats.ImageReader)

Example 5 with ImageReader

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();
    }
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) OMEXMLService(loci.formats.services.OMEXMLService)

Aggregations

ImageReader (loci.formats.ImageReader)71 ServiceFactory (loci.common.services.ServiceFactory)23 OMEXMLService (loci.formats.services.OMEXMLService)23 FormatException (loci.formats.FormatException)20 IFormatReader (loci.formats.IFormatReader)20 IMetadata (loci.formats.meta.IMetadata)19 Test (org.testng.annotations.Test)15 IOException (java.io.IOException)11 ChannelFiller (loci.formats.ChannelFiller)11 DependencyException (loci.common.services.DependencyException)10 ServiceException (loci.common.services.ServiceException)10 ChannelSeparator (loci.formats.ChannelSeparator)10 MinMaxCalculator (loci.formats.MinMaxCalculator)10 BufferedImageReader (loci.formats.gui.BufferedImageReader)8 ImageWriter (loci.formats.ImageWriter)7 File (java.io.File)6 FileStitcher (loci.formats.FileStitcher)6 OMETiffWriter (loci.formats.out.OMETiffWriter)6 Location (loci.common.Location)5 DimensionSwapper (loci.formats.DimensionSwapper)5