Search in sources :

Example 6 with ChannelSeparator

use of loci.formats.ChannelSeparator 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());
}
Also used : MinMaxCalculator(loci.formats.MinMaxCalculator) ChannelFiller(loci.formats.ChannelFiller) ImageReader(loci.formats.ImageReader) ChannelSeparator(loci.formats.ChannelSeparator) OMEXMLMetadataImpl(loci.formats.ome.OMEXMLMetadataImpl) Test(org.testng.annotations.Test)

Example 7 with ChannelSeparator

use of loci.formats.ChannelSeparator 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);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) Memoizer(loci.formats.Memoizer) ChannelMerger(loci.formats.ChannelMerger) ChannelFiller(loci.formats.ChannelFiller) BufferedImageReader(loci.formats.gui.BufferedImageReader) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) ChannelSeparator(loci.formats.ChannelSeparator) ServiceException(loci.common.services.ServiceException) FileStitcher(loci.formats.FileStitcher) MinMaxCalculator(loci.formats.MinMaxCalculator) MissingLibraryException(loci.formats.MissingLibraryException) DimensionSwapper(loci.formats.DimensionSwapper) ImageReader(loci.formats.ImageReader) BufferedImageReader(loci.formats.gui.BufferedImageReader) File(java.io.File) Location(loci.common.Location)

Example 8 with ChannelSeparator

use of loci.formats.ChannelSeparator in project bioformats by openmicroscopy.

the class Read_Image method run.

public void run(String arg) {
    OpenDialog od = new OpenDialog("Open Image File...", arg);
    String dir = od.getDirectory();
    String name = od.getFileName();
    String id = dir + name;
    ImageProcessorReader r = new ImageProcessorReader(new ChannelSeparator(LociPrefs.makeImageReader()));
    try {
        IJ.showStatus("Examining file " + name);
        r.setId(id);
        int num = r.getImageCount();
        int width = r.getSizeX();
        int height = r.getSizeY();
        ImageStack stack = new ImageStack(width, height);
        byte[][][] lookupTable = new byte[r.getSizeC()][][];
        for (int i = 0; i < num; i++) {
            IJ.showStatus("Reading image plane #" + (i + 1) + "/" + num);
            ImageProcessor ip = r.openProcessors(i)[0];
            stack.addSlice("" + (i + 1), ip);
            int channel = r.getZCTCoords(i)[1];
            lookupTable[channel] = r.get8BitLookupTable();
        }
        IJ.showStatus("Constructing image");
        ImagePlus imp = new ImagePlus(name, stack);
        ImagePlus colorizedImage = applyLookupTables(r, imp, lookupTable);
        r.close();
        colorizedImage.show();
        IJ.showStatus("");
    } catch (FormatException exc) {
        IJ.error("Sorry, an error occurred: " + exc.getMessage());
    } catch (IOException exc) {
        IJ.error("Sorry, an error occurred: " + exc.getMessage());
    }
}
Also used : ImageProcessor(ij.process.ImageProcessor) ImageProcessorReader(loci.plugins.util.ImageProcessorReader) ImageStack(ij.ImageStack) IOException(java.io.IOException) ImagePlus(ij.ImagePlus) ChannelSeparator(loci.formats.ChannelSeparator) FormatException(loci.formats.FormatException) OpenDialog(ij.io.OpenDialog)

Example 9 with ChannelSeparator

use of loci.formats.ChannelSeparator in project bioformats by openmicroscopy.

the class AFIReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    // The AFI file is just simple XML that lists the .svs files from
    // which to read pixel data.  Each .svs corresponds to a single channel;
    // we assemble the channels in the order in which they are stored in
    // the XML.
    // 
    // Note that the last two series are identical across the .svs files,
    // so we just use the ones from the first listed file.
    String xml = DataTools.readFile(id);
    XMLTools.parseXML(xml, new AFIHandler());
    String parent = new Location(id).getAbsoluteFile().getParent();
    String[] channelNames = new String[pixels.size()];
    reader = new ChannelSeparator[pixels.size()];
    for (int i = 0; i < pixels.size(); i++) {
        String file = pixels.get(i);
        int underscore = file.indexOf('_');
        int fullStop = file.indexOf('.');
        if (underscore >= 0 && fullStop > underscore) {
            channelNames[i] = file.substring(underscore + 1, fullStop);
        }
        pixels.set(i, new Location(parent, file).getAbsolutePath());
        reader[i] = new ChannelSeparator(new SVSReader());
        reader[i].setFlattenedResolutions(hasFlattenedResolutions());
        reader[i].setId(pixels.get(i));
    }
    core = reader[0].getCoreMetadataList();
    for (int i = 0; i < core.size() - EXTRA_IMAGES; i++) {
        CoreMetadata c = core.get(i);
        c.sizeC = pixels.size();
        c.imageCount = c.sizeC * c.sizeZ * c.sizeT;
        c.rgb = false;
        if (i == 0) {
            c.resolutionCount = core.size() - EXTRA_IMAGES;
        }
    }
    MetadataStore store = makeFilterMetadata();
    boolean minimalMetadata = getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM;
    MetadataTools.populatePixels(store, this, !minimalMetadata);
    String fileID = currentId.substring(currentId.lastIndexOf(File.separator) + 1, currentId.lastIndexOf("."));
    for (int i = 0; i < getSeriesCount(); i++) {
        store.setImageName(fileID + " - image #" + (i + 1), i);
    }
    if (!minimalMetadata) {
        Length[] emission = new Length[pixels.size()];
        Length[] excitation = new Length[pixels.size()];
        Double[] exposure = new Double[pixels.size()];
        Timestamp[] datestamp = new Timestamp[pixels.size()];
        Length[] physicalSizes = null;
        double magnification = Double.NaN;
        for (int c = 0; c < pixels.size(); c++) {
            SVSReader baseReader = (SVSReader) reader[c].getReader();
            emission[c] = baseReader.getEmission();
            excitation[c] = baseReader.getExcitation();
            exposure[c] = baseReader.getExposureTime();
            datestamp[c] = baseReader.getDatestamp();
            physicalSizes = baseReader.getPhysicalSizes();
            if (c == 0) {
                magnification = baseReader.getMagnification();
            }
        }
        String instrument = MetadataTools.createLSID("Instrument", 0);
        String objective = MetadataTools.createLSID("Objective", 0, 0);
        store.setInstrumentID(instrument, 0);
        store.setObjectiveID(objective, 0, 0);
        store.setObjectiveNominalMagnification(magnification, 0, 0);
        for (int i = 0; i < getSeriesCount() - EXTRA_IMAGES; i++) {
            if (datestamp[0] != null) {
                store.setImageAcquisitionDate(datestamp[0], i);
            }
            store.setImageInstrumentRef(instrument, i);
            store.setObjectiveSettingsID(objective, i);
            if (i < physicalSizes.length && physicalSizes[i] != null && physicalSizes[i].value(UNITS.MICROMETER).doubleValue() - Constants.EPSILON > 0) {
                Length size = physicalSizes[i];
                store.setPixelsPhysicalSizeX(size, i);
                store.setPixelsPhysicalSizeY(size, i);
            }
            for (int c = 0; c < channelNames.length; c++) {
                store.setChannelName(channelNames[c], i, c);
                if (emission[c] != null) {
                    store.setChannelEmissionWavelength(emission[c], i, c);
                }
                if (excitation[c] != null) {
                    store.setChannelExcitationWavelength(excitation[c], i, c);
                }
                store.setPlaneExposureTime(FormatTools.createTime(exposure[c], UNITS.SECOND), i, c);
            }
        }
    }
}
Also used : CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp) ChannelSeparator(loci.formats.ChannelSeparator) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) Location(loci.common.Location)

Example 10 with ChannelSeparator

use of loci.formats.ChannelSeparator in project bioformats by openmicroscopy.

the class AFIReader method close.

/* @see loci.formats.IFormatReader#close(boolean) */
@Override
public void close(boolean fileOnly) throws IOException {
    super.close(fileOnly);
    if (!fileOnly) {
        if (reader != null) {
            for (ChannelSeparator r : reader) {
                if (r != null) {
                    r.close();
                }
            }
        }
        reader = null;
        pixels.clear();
    }
}
Also used : ChannelSeparator(loci.formats.ChannelSeparator)

Aggregations

ChannelSeparator (loci.formats.ChannelSeparator)17 ChannelFiller (loci.formats.ChannelFiller)11 MinMaxCalculator (loci.formats.MinMaxCalculator)11 ImageReader (loci.formats.ImageReader)10 FormatException (loci.formats.FormatException)8 IOException (java.io.IOException)6 IFormatReader (loci.formats.IFormatReader)6 ChannelMerger (loci.formats.ChannelMerger)5 DimensionSwapper (loci.formats.DimensionSwapper)5 Test (org.testng.annotations.Test)5 Location (loci.common.Location)4 FileStitcher (loci.formats.FileStitcher)4 OMEXMLMetadataImpl (loci.formats.ome.OMEXMLMetadataImpl)4 MetadataStore (loci.formats.meta.MetadataStore)3 DataProvider (org.testng.annotations.DataProvider)3 RandomAccessInputStream (loci.common.RandomAccessInputStream)2 DependencyException (loci.common.services.DependencyException)2 ServiceException (loci.common.services.ServiceException)2 ServiceFactory (loci.common.services.ServiceFactory)2 CoreMetadata (loci.formats.CoreMetadata)2