use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.
the class VectraReader method initMetadataStore.
/* @see loci.formats.BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
super.initMetadataStore();
MetadataStore store = makeFilterMetadata();
for (int i = 0; i < getSeriesCount(); i++) {
int coreIndex = seriesToCoreIndex(i);
store.setImageName(getImageName(coreIndex), i);
store.setImageDescription("", i);
int ifdIndex = getIFDIndex(coreIndex, 0);
IFD ifd = ifds.get(ifdIndex);
double x = ifd.getXResolution();
double y = ifd.getYResolution();
store.setPixelsPhysicalSizeX(FormatTools.getPhysicalSizeX(x), i);
store.setPixelsPhysicalSizeY(FormatTools.getPhysicalSizeY(y), i);
}
for (int c = 0; c < getSizeC(); c++) {
String xml = getIFDComment(c);
try {
Element root = XMLTools.parseDOM(xml).getDocumentElement();
NodeList children = root.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (!(children.item(i) instanceof Element)) {
continue;
}
Element e = (Element) children.item(i);
String name = e.getNodeName();
String value = e.getTextContent();
if (name.equals("ScanProfile")) {
try {
Document profileRoot = XMLTools.createDocument();
Node tmp = profileRoot.importNode(e, true);
profileRoot.appendChild(tmp);
profileXML = XMLTools.getXML(profileRoot);
// scan profile XML is usually too long to be saved
// when original metadata filtering is enabled, but there
// is an API method below to retrieve it
addGlobalMeta(name, profileXML);
} catch (Exception ex) {
LOGGER.debug("Could not preserve scan profile metadata", ex);
}
} else {
addGlobalMetaList(name, value);
}
if (name.equals("Name")) {
if (hasFlattenedResolutions()) {
for (int series = 0; series < pyramidDepth; series++) {
store.setChannelName(value, series, c);
}
} else {
store.setChannelName(value, 0, c);
}
} else if (name.equals("Color")) {
String[] components = value.split(",");
Color color = new Color(Integer.parseInt(components[0]), Integer.parseInt(components[1]), Integer.parseInt(components[2]), 255);
if (hasFlattenedResolutions()) {
for (int series = 0; series < pyramidDepth; series++) {
store.setChannelColor(color, series, c);
}
} else {
store.setChannelColor(color, 0, c);
}
} else if (name.equals("Objective") && c == 0) {
String instrument = MetadataTools.createLSID("Instrument", 0);
String objective = MetadataTools.createLSID("Objective", 0, 0);
store.setInstrumentID(instrument, 0);
store.setObjectiveID(objective, 0, 0);
store.setObjectiveModel(value, 0, 0);
try {
String mag = value.toLowerCase().replace("x", "");
Double magFactor = DataTools.parseDouble(mag);
store.setObjectiveNominalMagnification(magFactor, 0, 0);
} catch (NumberFormatException ex) {
LOGGER.info("Could not determine magnification: {}", value);
}
for (int series = 0; series < getSeriesCount(); series++) {
store.setImageInstrumentRef(instrument, series);
store.setObjectiveSettingsID(objective, series);
}
} else if (name.equals("ExposureTime")) {
Time exposure = new Time(DataTools.parseDouble(value), UNITS.MICROSECOND);
store.setPlaneExposureTime(exposure, 0, c);
store.setPlaneTheZ(new NonNegativeInteger(0), 0, c);
store.setPlaneTheT(new NonNegativeInteger(0), 0, c);
store.setPlaneTheC(new NonNegativeInteger(c), 0, c);
}
}
} catch (ParserConfigurationException | SAXException | IOException e) {
LOGGER.warn("Could not parse XML for channel {}", c);
LOGGER.debug("", e);
}
}
}
use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.
the class VectraReader method isThisType.
// -- IFormatReader API methods --
/* (non-Javadoc)
* @see loci.formats.FormatReader#isThisType(java.lang.String, boolean)
*/
@Override
public boolean isThisType(String name, boolean open) {
if (!open) {
return checkSuffix(name, "qptiff");
}
try (RandomAccessInputStream stream = new RandomAccessInputStream(name)) {
TiffParser tiffParser = new TiffParser(stream);
tiffParser.setDoCaching(false);
if (!tiffParser.isValidHeader()) {
return false;
}
IFD ifd = tiffParser.getFirstIFD();
if (ifd == null) {
return false;
}
tiffParser.fillInIFD(ifd);
String software = ifd.getIFDTextValue(IFD.SOFTWARE);
return software != null && software.startsWith(SOFTWARE_CHECK);
} catch (IOException e) {
LOGGER.debug("I/O exception during isThisType() evaluation.", e);
return false;
}
}
use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.
the class SVSReader method isThisType.
/* (non-Javadoc)
* @see loci.formats.FormatReader#isThisType(java.lang.String, boolean)
*/
@Override
public boolean isThisType(String name, boolean open) {
boolean isThisType = super.isThisType(name, open);
if (!isThisType && open) {
RandomAccessInputStream stream = null;
try {
stream = new RandomAccessInputStream(name);
TiffParser tiffParser = new TiffParser(stream);
tiffParser.setDoCaching(false);
if (!tiffParser.isValidHeader()) {
return false;
}
IFD ifd = tiffParser.getFirstIFD();
if (ifd == null) {
return false;
}
Object description = ifd.get(IFD.IMAGE_DESCRIPTION);
if (description != null) {
String imageDescription = null;
if (description instanceof TiffIFDEntry) {
Object value = tiffParser.getIFDValue((TiffIFDEntry) description);
if (value != null) {
imageDescription = value.toString();
}
} else if (description instanceof String) {
imageDescription = (String) description;
}
if (imageDescription != null && imageDescription.startsWith(APERIO_IMAGE_DESCRIPTION_PREFIX)) {
return true;
}
}
return false;
} catch (IOException e) {
LOGGER.debug("I/O exception during isThisType() evaluation.", e);
return false;
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException e) {
LOGGER.debug("I/O exception during stream closure.", e);
}
}
}
return isThisType;
}
use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.
the class SlidebookTiffReader method isThisType.
// -- IFormatReader API methods --
/* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */
@Override
public boolean isThisType(RandomAccessInputStream stream) throws IOException {
TiffParser tp = new TiffParser(stream);
IFD ifd = tp.getFirstIFD();
if (ifd == null)
return false;
String software = ifd.getIFDTextValue(IFD.SOFTWARE);
if (software == null)
return false;
return software.equals(SLIDEBOOK_MAGIC_STRING) && ifd.getComment().length() == 0 && (ifd.containsKey(X_POS_TAG) || ifd.containsKey(Y_POS_TAG) || ifd.containsKey(Z_POS_TAG) || ifd.containsKey(CHANNEL_TAG) || ifd.containsKey(PHYSICAL_SIZE_TAG) || ifd.containsKey(MAGNIFICATION_TAG));
}
use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.
the class SlidebookTiffReader method getFirstChannel.
private String getFirstChannel(String path) throws FormatException, IOException {
RandomAccessInputStream s = new RandomAccessInputStream(path);
TiffParser parser = new TiffParser(s);
IFD ifd = parser.getFirstIFD();
Object channel = ifd.getIFDValue(CHANNEL_TAG);
s.close();
parser.getStream().close();
return channel == null ? null : channel.toString();
}
Aggregations