use of ome.units.quantity.Length in project bioformats by openmicroscopy.
the class NDPIReader method initMetadataStore.
/* @see loci.formats.BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
super.initMetadataStore();
MetadataStore store = makeFilterMetadata();
String instrumentID = MetadataTools.createLSID("Instrument", 0);
String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
store.setInstrumentID(instrumentID, 0);
store.setObjectiveID(objectiveID, 0, 0);
if (instrumentModel != null) {
store.setMicroscopeModel(instrumentModel, 0);
}
if (magnification != null) {
store.setObjectiveNominalMagnification(magnification, 0, 0);
}
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageName("Series " + (i + 1), i);
store.setImageInstrumentRef(instrumentID, i);
store.setObjectiveSettingsID(objectiveID, i);
if (i > 0) {
int ifdIndex = getIFDIndex(i, 0);
String creationDate = ifds.get(ifdIndex).getIFDTextValue(IFD.DATE_TIME);
creationDate = DateTools.formatDate(creationDate, DATE_FORMATS, ".");
if (creationDate != null) {
store.setImageAcquisitionDate(new Timestamp(creationDate), i);
}
double xResolution = ifds.get(ifdIndex).getXResolution();
double yResolution = ifds.get(ifdIndex).getYResolution();
Length sizeX = FormatTools.getPhysicalSizeX(xResolution);
Length sizeY = FormatTools.getPhysicalSizeY(yResolution);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, i);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, i);
}
} else {
store.setImageDescription(serialNumber, i);
}
}
}
use of ome.units.quantity.Length in project bioformats by openmicroscopy.
the class NativeND2Reader method populateMetadataStore.
private void populateMetadataStore(ND2Handler handler) throws FormatException {
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, true);
String filename = new Location(getCurrentFile()).getName();
if (handler != null) {
ArrayList<String> posNames = handler.getPositionNames();
int nameWidth = String.valueOf(getSeriesCount()).length();
for (int i = 0; i < getSeriesCount(); i++) {
String seriesSuffix = String.format("(series %0" + nameWidth + "d)", i + 1);
String suffix = (i < posNames.size() && !posNames.get(i).equals("")) ? posNames.get(i) : seriesSuffix;
String name = filename + " " + suffix;
store.setImageName(name.trim(), i);
}
}
colors = new int[getEffectiveSizeC()];
ArrayList<String> channelNames = null;
if (handler != null) {
channelNames = handler.getChannelNames();
if (channelNames.size() < getEffectiveSizeC() && backupHandler != null) {
channelNames = backupHandler.getChannelNames();
} else if (channelNames.size() < getEffectiveSizeC()) {
channelNames = textChannelNames;
}
for (int c = 0; c < getEffectiveSizeC(); c++) {
if (c < channelNames.size()) {
String channelName = channelNames.get(c);
Integer channelColor = channelColors.get(channelName);
colors[c] = channelColor == null ? 0 : channelColor.intValue();
}
}
}
if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM) {
return;
}
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
for (int i = 0; i < getSeriesCount(); i++) {
// link Instrument and Image
store.setImageInstrumentRef(instrumentID, i);
// set the channel color
for (int c = 0; c < getEffectiveSizeC(); c++) {
int red = colors[c] & 0xff;
int green = (colors[c] & 0xff00) >> 8;
int blue = (colors[c] & 0xff0000) >> 16;
// doing so can prevent the image from displaying correctly
if (red != 0 || green != 0 || blue != 0) {
// always set the alpha to 255, otherwise the colors may not appear
store.setChannelColor(new Color(red, green, blue, 255), i, c);
}
}
}
// populate Dimensions data
if (handler != null) {
for (int i = 0; i < getSeriesCount(); i++) {
double sizeX = handler.getPixelSizeX();
double sizeY = handler.getPixelSizeY();
double sizeZ = handler.getPixelSizeZ();
if (trueSizeX > 0) {
store.setPixelsPhysicalSizeX(FormatTools.getPhysicalSizeX(trueSizeX), i);
} else {
Length size = FormatTools.getPhysicalSizeX(sizeX);
if (size != null) {
store.setPixelsPhysicalSizeX(size, i);
}
}
if (trueSizeY > 0) {
store.setPixelsPhysicalSizeY(FormatTools.getPhysicalSizeY(trueSizeY), i);
} else if (trueSizeX > 0) {
// if the X size is set, assume X and Y are equal
store.setPixelsPhysicalSizeY(FormatTools.getPhysicalSizeY(trueSizeX), i);
} else {
Length size = FormatTools.getPhysicalSizeY(sizeY);
if (size == null) {
// if the X size is set, assume X and Y are equal
size = FormatTools.getPhysicalSizeY(sizeX);
}
if (size != null) {
store.setPixelsPhysicalSizeY(size, i);
}
}
if (trueSizeZ != null && trueSizeZ > 0) {
store.setPixelsPhysicalSizeZ(FormatTools.getPhysicalSizeZ(trueSizeZ), i);
} else {
Length size = FormatTools.getPhysicalSizeZ(sizeZ);
if (size != null) {
store.setPixelsPhysicalSizeZ(size, i);
}
}
}
}
// populate PlaneTiming and StagePosition data
if (handler != null && handler.getExposureTimes().size() > 0) {
exposureTime = handler.getExposureTimes();
}
int zcPlanes = getImageCount() / ((split ? getSizeC() : 1) * getSizeT());
for (int i = 0; i < getSeriesCount(); i++) {
if (tsT.size() > 0) {
setSeries(i);
for (int n = 0; n < getImageCount(); n++) {
int[] coords = getZCTCoords(n);
int stampIndex = getIndex(coords[0], split ? 0 : coords[1], 0);
stampIndex += (coords[2] * getSeriesCount() + i) * zcPlanes;
if (tsT.size() == getImageCount())
stampIndex = n;
else if (tsT.size() == getSizeZ()) {
stampIndex = coords[0];
}
if (stampIndex < tsT.size()) {
double stamp = tsT.get(stampIndex).doubleValue();
store.setPlaneDeltaT(new Time(stamp, UNITS.SECOND), i, n);
}
int index = i * getSizeC() + coords[1];
if (exposureTime.size() == getSizeC()) {
index = coords[1];
}
if (exposureTime != null && index < exposureTime.size() && exposureTime.get(index) != null) {
store.setPlaneExposureTime(new Time(exposureTime.get(index), UNITS.SECOND), i, n);
}
}
}
if (handler != null) {
if (posX == null)
posX = handler.getXPositions();
if (posY == null)
posY = handler.getYPositions();
if (posZ == null)
posZ = handler.getZPositions();
}
String pos = "for position";
for (int n = 0; n < getImageCount(); n++) {
int[] coords = getZCTCoords(n);
int index = coords[0];
index += (coords[2] * getSeriesCount() + i) * zcPlanes;
if (posX != null) {
if (index >= posX.size())
index = i;
if (index < posX.size()) {
String key = "X position ";
store.setPlanePositionX(posX.get(index), i, n);
addSeriesMetaList(key, posX.get(index));
addGlobalMetaList(key + pos, posX.get(index));
}
}
if (posY != null) {
if (index < posY.size()) {
String key = "Y position ";
store.setPlanePositionY(posY.get(index), i, n);
addSeriesMetaList(key, posY.get(index));
addGlobalMetaList(key + pos, posY.get(index));
}
}
if (posZ != null) {
if (index < posZ.size()) {
store.setPlanePositionZ(posZ.get(index), i, n);
String key = "Z position " + pos + ", plane";
addSeriesMetaList(key, posZ.get(index));
addGlobalMetaList(key, posZ.get(index));
}
}
}
}
if (handler == null) {
setSeries(0);
return;
}
String detectorID = MetadataTools.createLSID("Detector", 0, 0);
store.setDetectorID(detectorID, 0, 0);
store.setDetectorModel(handler.getCameraModel(), 0, 0);
store.setDetectorType(getDetectorType("Other"), 0, 0);
ArrayList<String> modality = handler.getModalities();
ArrayList<String> binning = handler.getBinnings();
ArrayList<Double> speed = handler.getSpeeds();
ArrayList<Double> gain = handler.getGains();
ArrayList<Double> temperature = handler.getTemperatures();
ArrayList<Double> exWave = handler.getExcitationWavelengths();
ArrayList<Double> emWave = handler.getEmissionWavelengths();
ArrayList<Integer> power = handler.getPowers();
ArrayList<Hashtable<String, String>> rois = handler.getROIs();
if (backupHandler != null) {
if (emWave.size() == 0) {
emWave = backupHandler.getEmissionWavelengths();
}
if (exWave.size() == 0) {
exWave = backupHandler.getExcitationWavelengths();
}
}
for (int i = 0; i < getSeriesCount(); i++) {
for (int c = 0; c < getEffectiveSizeC(); c++) {
int index = c;
Double pinholeSize = handler.getPinholeSize();
if (pinholeSize != null) {
store.setChannelPinholeSize(new Length(pinholeSize, UNITS.MICROMETER), i, c);
}
if (index < channelNames.size()) {
String channelName = channelNames.get(index);
store.setChannelName(channelName, i, c);
} else if (channelNames.size() >= getEffectiveSizeC()) {
store.setChannelName(channelNames.get(c), i, c);
}
if (index < modality.size()) {
store.setChannelAcquisitionMode(getAcquisitionMode(modality.get(index)), i, c);
}
if (index < emWave.size() || index < textEmissionWavelengths.size()) {
Double value = index < emWave.size() ? emWave.get(index) : textEmissionWavelengths.get(index);
Length emission = FormatTools.getEmissionWavelength(value);
if (emission != null) {
store.setChannelEmissionWavelength(emission, i, c);
}
} else if (emWave.size() > 0 || textEmissionWavelengths.size() > 0) {
store.setChannelColor(new Color(255, 255, 255, 255), i, c);
}
if (index < exWave.size()) {
Length excitation = FormatTools.getExcitationWavelength(exWave.get(index));
if (excitation != null) {
store.setChannelExcitationWavelength(excitation, i, c);
}
}
if (index < binning.size()) {
store.setDetectorSettingsBinning(getBinning(binning.get(index)), i, c);
}
if (index < gain.size()) {
store.setDetectorSettingsGain(gain.get(index), i, c);
}
if (index < speed.size()) {
store.setDetectorSettingsReadOutRate(new Frequency(speed.get(index), UNITS.HERTZ), i, c);
}
store.setDetectorSettingsID(detectorID, i, c);
}
}
for (int i = 0; i < getSeriesCount(); i++) {
if (i * getSizeC() < temperature.size()) {
Double temp = temperature.get(i * getSizeC());
store.setImagingEnvironmentTemperature(new Temperature(temp, UNITS.CELSIUS), i);
}
}
// populate DetectorSettings
Double voltage = handler.getVoltage();
if (voltage != null) {
store.setDetectorSettingsVoltage(new ElectricPotential(voltage, UNITS.VOLT), 0, 0);
}
// populate Objective
Double na = handler.getNumericalAperture();
if (na != null) {
store.setObjectiveLensNA(na, 0, 0);
}
Double mag = handler.getMagnification();
if (mag != null) {
store.setObjectiveCalibratedMagnification(mag, 0, 0);
}
store.setObjectiveModel(handler.getObjectiveModel(), 0, 0);
String immersion = handler.getImmersion();
if (immersion == null)
immersion = "Other";
store.setObjectiveImmersion(getImmersion(immersion), 0, 0);
String correction = handler.getCorrection();
if (correction == null || correction.length() == 0)
correction = "Other";
store.setObjectiveCorrection(getCorrection(correction), 0, 0);
// link Objective to Image
String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
store.setObjectiveID(objectiveID, 0, 0);
if (refractiveIndex == null) {
refractiveIndex = handler.getRefractiveIndex();
}
for (int i = 0; i < getSeriesCount(); i++) {
store.setObjectiveSettingsID(objectiveID, i);
if (refractiveIndex != null) {
store.setObjectiveSettingsRefractiveIndex(refractiveIndex, i);
}
}
setSeries(0);
if (getMetadataOptions().getMetadataLevel() == MetadataLevel.NO_OVERLAYS) {
return;
}
handler.populateROIs(store);
}
use of ome.units.quantity.Length in project bioformats by openmicroscopy.
the class OIRReader method parseImageProperties.
private void parseImageProperties(Element root) throws FormatException {
CoreMetadata m = core.get(0);
Element general = getFirstChild(root, "commonimage:general");
if (general != null) {
Element creationDate = getFirstChild(general, "base:creationDateTime");
if (creationDate != null) {
String date = creationDate.getTextContent();
acquisitionDate = new Timestamp(date);
}
}
Element lsm = getFirstChild(root, "commonimage:lsm");
if (lsm != null) {
NodeList laserNodes = lsm.getElementsByTagName("commonimage:laser");
for (int i = 0; i < laserNodes.getLength(); i++) {
Element laser = (Element) laserNodes.item(i);
Element idNode = getFirstChild(laser, "commonimage:id");
Element nameNode = getFirstChild(laser, "commonimage:name");
Laser l = new Laser();
if (idNode != null) {
l.id = idNode.getTextContent();
}
if (nameNode != null) {
l.name = nameNode.getTextContent();
}
lasers.add(l);
}
}
Element imageInfo = getFirstChild(root, "commonimage:imageInfo");
if (imageInfo != null) {
Element width = getFirstChild(imageInfo, "commonimage:width");
Element height = getFirstChild(imageInfo, "commonimage:height");
if (width != null && getSizeX() == 0) {
m.sizeX = Integer.parseInt(width.getTextContent());
}
if (height != null && getSizeY() == 0) {
m.sizeY = Integer.parseInt(height.getTextContent());
}
NodeList axisNodes = imageInfo.getElementsByTagName("commonimage:axis");
if (axisNodes != null) {
for (int i = 0; i < axisNodes.getLength(); i++) {
parseAxis((Element) axisNodes.item(i));
}
}
NodeList channelNodes = imageInfo.getElementsByTagName("commonphase:channel");
for (int i = 0; i < channelNodes.getLength(); i++) {
Channel c = new Channel();
Element channelNode = (Element) channelNodes.item(i);
c.id = channelNode.getAttribute("id");
int index = Integer.parseInt(channelNode.getAttribute("order")) - 1;
Element name = getFirstChild(channelNode, "commonphase:name");
if (name != null) {
c.name = name.getTextContent();
}
Element pinhole = getFirstChild(channelNode, "fvCommonphase:pinholeDiameter");
if (pinhole != null) {
Double pinholeSize = DataTools.parseDouble(pinhole.getTextContent());
if (pinholeSize != null) {
c.pinhole = new Length(pinholeSize, UNITS.MICROMETER);
}
}
Element startWavelength = getFirstChild(channelNode, "opticalelement:startWavelength");
Element endWavelength = getFirstChild(channelNode, "opticalelement:endWavelength");
if (startWavelength != null) {
Double wave = DataTools.parseDouble(startWavelength.getTextContent());
if (wave != null) {
c.excitation = FormatTools.getExcitationWavelength(wave);
}
}
if (endWavelength != null) {
Double wave = DataTools.parseDouble(endWavelength.getTextContent());
if (wave != null) {
c.emission = FormatTools.getEmissionWavelength(wave);
}
}
Element imageDefinition = getFirstChild(channelNode, "commonphase:imageDefinition");
if (imageDefinition != null) {
Element depth = getFirstChild(imageDefinition, "commonphase:depth");
Element bitCount = getFirstChild(imageDefinition, "commonphase:bitCounts");
if (depth != null) {
int bytes = Integer.parseInt(depth.getTextContent());
m.pixelType = FormatTools.pixelTypeFromBytes(bytes, false, false);
}
if (bitCount != null) {
m.bitsPerPixel = Integer.parseInt(bitCount.getTextContent());
}
}
Element length = getFirstChild(channelNode, "commonphase:length");
Element pixelUnit = getFirstChild(channelNode, "commonphase:pixelUnit");
if (length != null) {
Element xLength = getFirstChild(length, "commonparam:x");
Element xUnit = getFirstChild(pixelUnit, "commonphase:x");
if (xLength != null) {
Double x = DataTools.parseDouble(xLength.getTextContent());
String unit = null;
if (xUnit != null) {
unit = xUnit.getTextContent();
}
physicalSizeX = FormatTools.getPhysicalSize(x, unit);
}
Element yLength = getFirstChild(length, "commonparam:y");
Element yUnit = getFirstChild(pixelUnit, "commonphase:y");
if (yLength != null) {
Double y = DataTools.parseDouble(yLength.getTextContent());
String unit = null;
if (yUnit != null) {
unit = yUnit.getTextContent();
}
physicalSizeY = FormatTools.getPhysicalSize(y, unit);
}
Element zLength = getFirstChild(length, "commonparam:z");
Element zUnit = getFirstChild(pixelUnit, "commonphase:z");
if (zLength != null) {
Double z = DataTools.parseDouble(zLength.getTextContent());
String unit = null;
if (zUnit != null) {
unit = zUnit.getTextContent();
}
physicalSizeZ = FormatTools.getPhysicalSize(z, unit);
}
}
while (index > channels.size()) {
channels.add(null);
}
if (index == channels.size()) {
channels.add(c);
} else {
channels.set(index, c);
}
}
}
for (int i = 0; i < channels.size(); i++) {
if (channels.get(i) == null) {
channels.remove(i);
i--;
}
}
Element acquisition = getFirstChild(root, "commonimage:acquisition");
if (acquisition == null) {
acquisition = getFirstChild(root, "lsmimage:acquisition");
}
if (acquisition != null) {
Element microscopeConfiguration = getFirstChild(acquisition, "commonimage:microscopeConfiguration");
if (microscopeConfiguration != null) {
NodeList objectiveLenses = microscopeConfiguration.getElementsByTagName("commonimage:objectiveLens");
if (objectiveLenses != null) {
for (int i = 0; i < objectiveLenses.getLength(); i++) {
Element lens = (Element) objectiveLenses.item(i);
Objective objective = new Objective();
Element lensName = getFirstChild(lens, "opticalelement:displayName");
Element magnification = getFirstChild(lens, "opticalelement:magnification");
Element na = getFirstChild(lens, "opticalelement:naValue");
Element wd = getFirstChild(lens, "opticalelement:wdValue");
Element refraction = getFirstChild(lens, "opticalelement:refraction");
Element immersion = getFirstChild(lens, "opticalelement:immersion");
if (lensName != null) {
objective.name = lensName.getTextContent();
}
if (magnification != null) {
objective.magnification = DataTools.parseDouble(magnification.getTextContent());
}
if (na != null) {
objective.na = DataTools.parseDouble(na.getTextContent());
}
if (wd != null) {
objective.wd = DataTools.parseDouble(wd.getTextContent());
}
if (refraction != null) {
objective.ri = DataTools.parseDouble(refraction.getTextContent());
}
if (immersion != null) {
objective.immersion = getImmersion(immersion.getTextContent());
}
objectives.add(objective);
}
}
}
Element imagingParam = getFirstChild(acquisition, "commonimage:imagingParam");
if (imagingParam == null) {
imagingParam = getFirstChild(acquisition, "lsmimage:imagingParam");
}
if (imagingParam != null) {
NodeList axes = imagingParam.getElementsByTagName("commonparam:axis");
if (axes != null) {
for (int i = 0; i < axes.getLength(); i++) {
Element dimensionAxis = (Element) axes.item(i);
if (dimensionAxis.hasAttribute("enable") && dimensionAxis.getAttribute("enable").equals("true") && (!dimensionAxis.hasAttribute("paramEnable") || dimensionAxis.getAttribute("paramEnable").equals("true"))) {
parseAxis(dimensionAxis);
}
}
}
NodeList pmts = imagingParam.getElementsByTagName("lsmparam:pmt");
if (pmts != null) {
for (int i = 0; i < pmts.getLength(); i++) {
Element pmt = (Element) pmts.item(i);
Detector detector = new Detector();
detector.id = pmt.getAttribute("detectorId");
detector.channelId = pmt.getAttribute("channelId");
Element voltage = getFirstChild(pmt, "lsmparam:voltage");
Element offset = getFirstChild(pmt, "lsmparam:offset");
Element gain = getFirstChild(pmt, "lsmparam:gain");
if (voltage != null) {
detector.voltage = DataTools.parseDouble(voltage.getTextContent());
}
if (offset != null) {
detector.offset = DataTools.parseDouble(offset.getTextContent());
}
if (gain != null) {
detector.gain = DataTools.parseDouble(gain.getTextContent());
}
detectors.add(detector);
}
}
NodeList mainLasers = imagingParam.getElementsByTagName("lsmparam:mainLaser");
if (mainLasers != null) {
for (int i = 0; i < mainLasers.getLength(); i++) {
Element mainLaser = (Element) mainLasers.item(i);
String id = mainLaser.getAttribute("laserDataId");
Laser currentLaser = null;
for (int laser = 0; laser < lasers.size(); laser++) {
if (id.startsWith(lasers.get(laser).id)) {
currentLaser = lasers.get(laser);
break;
}
}
if (currentLaser == null) {
continue;
}
currentLaser.dataId = id;
Element power = getFirstChild(mainLaser, "commonparam:power");
Element transmissivity = getFirstChild(mainLaser, "commonparam:transmissivity");
if (power != null) {
currentLaser.power = DataTools.parseDouble(power.getTextContent());
}
if (transmissivity != null) {
currentLaser.transmissivity = DataTools.parseDouble(transmissivity.getTextContent());
}
}
}
Element resolution = getFirstChild(imagingParam, "commonparam:pixelResolution");
if (resolution != null) {
Element x = getFirstChild(resolution, "commonparam:x");
Element y = getFirstChild(resolution, "commonparam:y");
Element z = getFirstChild(resolution, "commonparam:z");
if (x != null && physicalSizeX == null) {
Double xValue = DataTools.parseDouble(x.getTextContent());
physicalSizeX = FormatTools.getPhysicalSize(xValue, null);
}
if (y != null && physicalSizeY == null) {
Double yValue = DataTools.parseDouble(y.getTextContent());
physicalSizeY = FormatTools.getPhysicalSize(yValue, null);
}
if (z != null && physicalSizeZ == null) {
Double zValue = DataTools.parseDouble(z.getTextContent());
physicalSizeZ = FormatTools.getPhysicalSize(zValue, null);
}
}
}
NodeList imagingMainLasers = acquisition.getElementsByTagName("lsmimage:imagingMainLaser");
if (imagingMainLasers != null) {
for (int i = 0; i < imagingMainLasers.getLength(); i++) {
Element mainLaser = (Element) imagingMainLasers.item(i);
String id = mainLaser.getAttribute("id");
String enable = mainLaser.getAttribute("enable");
if ("true".equals(enable)) {
Element wavelength = getFirstChild(mainLaser, "commonimage:wavelength");
if (wavelength != null) {
for (Laser l : lasers) {
if (id.equals(l.dataId)) {
l.wavelength = DataTools.parseDouble(wavelength.getTextContent());
}
}
}
}
}
}
NodeList channelLinkages = acquisition.getElementsByTagName("commonphase:channel");
// if not, clear and re-populate the channel list
for (int c = 0; c < channels.size(); c++) {
String id = channels.get(c).id;
boolean hasUID = false;
for (String uid : pixelBlocks.keySet()) {
if (uid.indexOf(id) >= 0) {
hasUID = true;
break;
}
}
if (!hasUID) {
channels.remove(c);
c--;
}
}
boolean appendChannels = channels.size() == 0;
if (channelLinkages != null && channelLinkages.getLength() > 0) {
for (int i = 0; i < channelLinkages.getLength(); i++) {
Element channel = (Element) channelLinkages.item(i);
parseChannel(channel, appendChannels);
}
} else {
// so far seems to only be needed for the oldest (software version 1.2.x) files
channelLinkages = acquisition.getElementsByTagName("lsmimage:channel");
for (int i = 0; i < channelLinkages.getLength(); i++) {
Element channel = (Element) channelLinkages.item(i);
parseChannel(channel, appendChannels);
}
}
}
}
use of ome.units.quantity.Length in project bioformats by openmicroscopy.
the class OxfordInstrumentsReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
in = new RandomAccessInputStream(id);
CoreMetadata m = core.get(0);
m.littleEndian = true;
in.order(isLittleEndian());
in.seek(48);
String comment = in.readString(32);
String dateTime = readDate();
in.skipBytes(8);
double xSize = -in.readFloat() + in.readFloat();
in.skipBytes(20);
double ySize = -in.readFloat() + in.readFloat();
in.skipBytes(24);
double zMin = in.readFloat();
double zMax = in.readFloat();
in.skipBytes(864);
m.sizeX = in.readInt();
m.sizeY = in.readInt();
in.skipBytes(28);
if (getSizeX() == 0 && getSizeY() == 0) {
m.sizeX = in.readInt();
m.sizeY = in.readInt();
in.skipBytes(196);
} else
in.skipBytes(204);
m.pixelType = FormatTools.UINT16;
m.sizeZ = 1;
m.sizeC = 1;
m.sizeT = 1;
m.imageCount = 1;
m.rgb = false;
m.indexed = false;
m.dimensionOrder = "XYZCT";
m.interleaved = false;
if (FormatTools.getPlaneSize(this) + in.getFilePointer() > in.length()) {
m.sizeY = 1;
}
int lutSize = in.readInt();
in.skipBytes(lutSize);
headerSize = in.getFilePointer();
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
in.skipBytes(FormatTools.getPlaneSize(this));
int nMetadataStrings = in.readInt();
for (int i = 0; i < nMetadataStrings; i++) {
int length = in.readInt();
String s = in.readString(length);
if (s.indexOf(':') != -1) {
String key = s.substring(0, s.indexOf(':')).trim();
String value = s.substring(s.indexOf(':') + 1).trim();
if (!value.equals("-")) {
addGlobalMeta(key, value);
}
}
}
addGlobalMeta("Description", comment);
addGlobalMeta("Acquisition date", dateTime);
addGlobalMeta("X size (um)", xSize);
addGlobalMeta("Y size (um)", ySize);
addGlobalMeta("Z minimum (um)", zMin);
addGlobalMeta("Z maximum (um)", zMax);
}
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
store.setImageDescription(comment, 0);
if (dateTime != null) {
store.setImageAcquisitionDate(new Timestamp(dateTime), 0);
}
double physicalSizeX = xSize / getSizeX();
double physicalSizeY = ySize / getSizeY();
Length sizeX = FormatTools.getPhysicalSizeX(physicalSizeX);
Length sizeY = FormatTools.getPhysicalSizeY(physicalSizeY);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
}
use of ome.units.quantity.Length in project bioformats by openmicroscopy.
the class LEOReader method initMetadataStore.
/* @see BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
super.initMetadataStore();
MetadataStore store = makeFilterMetadata();
date = DateTools.formatDate(date, "HH:mm dd-MMM-yyyy");
if (date != null) {
store.setImageAcquisitionDate(new Timestamp(date), 0);
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
Length sizeX = FormatTools.getPhysicalSizeX(xSize);
Length sizeY = FormatTools.getPhysicalSizeY(xSize);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
String instrument = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrument, 0);
store.setImageInstrumentRef(instrument, 0);
store.setObjectiveID(MetadataTools.createLSID("Objective", 0, 0), 0, 0);
store.setObjectiveWorkingDistance(new Length(workingDistance, UNITS.MICROMETER), 0, 0);
store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
}
}
Aggregations