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());
}
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);
}
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());
}
}
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);
}
}
}
}
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();
}
}
Aggregations