use of ome.xml.model.primitives.Color in project bioformats by openmicroscopy.
the class ImarisHDFReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
try {
ServiceFactory factory = new ServiceFactory();
netcdf = factory.getInstance(NetCDFService.class);
netcdf.setFile(id);
} catch (DependencyException e) {
throw new MissingLibraryException(NetCDFServiceImpl.NO_NETCDF_MSG, e);
}
pixelSizeX = pixelSizeY = pixelSizeZ = 1;
emWave = new ArrayList<String>();
exWave = new ArrayList<String>();
channelMin = new ArrayList<String>();
channelMax = new ArrayList<String>();
gain = new ArrayList<String>();
pinhole = new ArrayList<String>();
channelName = new ArrayList<String>();
microscopyMode = new ArrayList<String>();
colors = new ArrayList<double[]>();
seriesCount = 0;
// read all of the metadata key/value pairs
parseAttributes();
CoreMetadata ms0 = core.get(0);
if (seriesCount > 1) {
for (int i = 1; i < seriesCount; i++) {
core.add(new CoreMetadata());
}
for (int i = 1; i < seriesCount; i++) {
CoreMetadata ms = core.get(i);
String groupPath = "DataSet/ResolutionLevel_" + i + "/TimePoint_0/Channel_0";
ms.sizeX = Integer.parseInt(netcdf.getAttributeValue(groupPath + "/ImageSizeX"));
ms.sizeY = Integer.parseInt(netcdf.getAttributeValue(groupPath + "/ImageSizeY"));
ms.sizeZ = Integer.parseInt(netcdf.getAttributeValue(groupPath + "/ImageSizeZ"));
ms.imageCount = ms.sizeZ * getSizeC() * getSizeT();
ms.sizeC = getSizeC();
ms.sizeT = getSizeT();
ms.thumbnail = true;
if (ms.sizeZ == ms0.sizeZ && ms.sizeC == ms0.sizeC && ms.sizeT == ms0.sizeT) {
// do not assume that all series will have the same dimensions
// if the Z, C or T size is different, then it cannot
// be a subresolution
ms0.resolutionCount++;
}
}
}
ms0.imageCount = getSizeZ() * getSizeC() * getSizeT();
ms0.thumbnail = false;
ms0.dimensionOrder = "XYZCT";
// determine pixel type - this isn't stored in the metadata, so we need
// to check the pixels themselves
int type = -1;
Object pix = getImageData(0, 0, 0, 1, 1);
if (pix instanceof byte[][])
type = FormatTools.UINT8;
else if (pix instanceof short[][])
type = FormatTools.UINT16;
else if (pix instanceof int[][])
type = FormatTools.UINT32;
else if (pix instanceof float[][])
type = FormatTools.FLOAT;
else if (pix instanceof double[][])
type = FormatTools.DOUBLE;
else {
throw new FormatException("Unknown pixel type: " + pix);
}
for (int i = 0; i < core.size(); i++) {
CoreMetadata ms = core.get(i);
ms.pixelType = type;
ms.dimensionOrder = "XYZCT";
ms.rgb = false;
ms.thumbSizeX = 128;
ms.thumbSizeY = 128;
ms.orderCertain = true;
ms.littleEndian = true;
ms.interleaved = false;
ms.indexed = colors.size() >= getSizeC();
}
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
String imageName = new Location(getCurrentFile()).getName();
for (int s = 0; s < getSeriesCount(); s++) {
store.setImageName(imageName + " Resolution Level " + (s + 1), s);
}
if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM) {
return;
}
int cIndex = 0;
for (int s = 0; s < getSeriesCount(); s++) {
setSeries(s);
double px = pixelSizeX, py = pixelSizeY, pz = pixelSizeZ;
if (px == 1)
px = (maxX - minX) / getSizeX();
if (py == 1)
py = (maxY - minY) / getSizeY();
if (pz == 1)
pz = (maxZ - minZ) / getSizeZ();
Length sizeX = FormatTools.getPhysicalSizeX(px);
Length sizeY = FormatTools.getPhysicalSizeY(py);
Length sizeZ = FormatTools.getPhysicalSizeZ(pz);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, s);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, s);
}
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, s);
}
for (int i = 0; i < getSizeC(); i++, cIndex++) {
Float gainValue = null;
Integer pinholeValue = null, emWaveValue = null, exWaveValue;
if (cIndex < gain.size()) {
try {
gainValue = new Float(gain.get(cIndex));
} catch (NumberFormatException e) {
}
}
if (cIndex < pinhole.size()) {
try {
pinholeValue = new Integer(pinhole.get(cIndex));
} catch (NumberFormatException e) {
}
}
if (cIndex < emWave.size()) {
try {
emWaveValue = new Integer(emWave.get(cIndex));
} catch (NumberFormatException e) {
}
}
if (cIndex < exWave.size()) {
try {
exWaveValue = new Integer(exWave.get(cIndex));
} catch (NumberFormatException e) {
}
}
Double minValue = null, maxValue = null;
if (cIndex < channelMin.size()) {
try {
minValue = new Double(channelMin.get(cIndex));
} catch (NumberFormatException e) {
}
}
if (cIndex < channelMax.size()) {
try {
maxValue = new Double(channelMax.get(cIndex));
} catch (NumberFormatException e) {
}
}
if (i < colors.size()) {
double[] color = colors.get(i);
Color realColor = new Color((int) (color[0] * 255), (int) (color[1] * 255), (int) (color[2] * 255), 255);
store.setChannelColor(realColor, s, i);
}
}
}
setSeries(0);
}
use of ome.xml.model.primitives.Color in project bioformats by openmicroscopy.
the class GatanReader method parseTags.
// -- Helper methods --
/**
* Parses Gatan DM3 tags.
* Information on the DM3 structure found at:
* http://rsb.info.nih.gov/ij/plugins/DM3Format.gj.html and
* http://www-hrem.msm.cam.ac.uk/~cbb/info/dmformat/
*
* The basic structure is this: the file is comprised of a list of tags.
* Each tag is either a data tag or a group tag. Group tags are simply
* containers for more group and data tags, where data tags contain actual
* metadata. Each data tag is comprised of a type (byte, short, etc.),
* a label, and a value.
*/
private void parseTags(int numTags, String parent, String indent) throws FormatException, IOException, ParseException {
for (int i = 0; i < numTags; i++) {
if (in.getFilePointer() + 3 >= in.length())
break;
// can be 21 (data) or 20 (tag group)
byte type = in.readByte();
int length = in.readShort();
// image data is in tag with type 21 and label 'Data'
// image dimensions are in type 20 tag with 2 type 15 tags
// bytes per pixel is in type 21 tag with label 'PixelDepth'
String labelString = null;
String value = null;
if (type == VALUE) {
labelString = in.readByteToString(length);
skipPadding();
skipPadding();
// equal to '%%%%' / 623191333
int skip = in.readInt();
skipPadding();
int n = in.readInt();
skipPadding();
int dataType = in.readInt();
String sb = labelString;
if (sb.length() > 32) {
sb = sb.substring(0, 20) + "... (" + sb.length() + ")";
}
LOGGER.debug("{}{}: n={}, dataType={}, label={}", new Object[] { indent, i, n, dataType, sb });
if (skip != 623191333)
LOGGER.warn("Skip mismatch: {}", skip);
if (n == 1) {
if ("Dimensions".equals(parent) && labelString.length() == 0) {
if (adjustEndianness)
in.order(!in.isLittleEndian());
if (i == 0) {
core.get(0).sizeX = in.readInt();
} else if (i == 1)
core.get(0).sizeY = in.readInt();
else if (i == 2) {
core.get(0).sizeZ = in.readInt();
}
if (adjustEndianness)
in.order(!in.isLittleEndian());
} else
value = String.valueOf(readValue(dataType));
} else if (n == 2) {
if (dataType == 18) {
// this should always be true
length = in.readInt();
} else
LOGGER.warn("dataType mismatch: {}", dataType);
value = in.readString(length);
} else if (n == 3) {
if (dataType == GROUP) {
// this should always be true
skipPadding();
dataType = in.readInt();
long dataLength = 0;
if (version == 4) {
dataLength = in.readLong();
} else {
dataLength = in.readInt();
}
length = (int) (dataLength & 0xffffffff);
if (labelString.equals("Data")) {
if (dataLength > 0) {
pixelOffset = in.getFilePointer();
in.seek(in.getFilePointer() + getNumBytes(dataType) * dataLength);
numPixelBytes = in.getFilePointer() - pixelOffset;
}
} else {
if (dataType == 10)
in.skipBytes(length);
else
value = in.readByteToString(length * 2);
}
} else
LOGGER.warn("dataType mismatch: {}", dataType);
} else {
// this is a normal struct of simple types
if (dataType == ARRAY) {
in.skipBytes(4);
skipPadding();
skipPadding();
int numFields = in.readInt();
long startFP = in.getFilePointer();
final StringBuilder s = new StringBuilder();
in.skipBytes(4);
skipPadding();
long baseFP = in.getFilePointer();
if (version == 4) {
baseFP += 4;
}
int width = version == 4 ? 16 : 8;
for (int j = 0; j < numFields; j++) {
in.seek(baseFP + j * width);
dataType = in.readInt();
in.seek(startFP + numFields * width + j * getNumBytes(dataType));
s.append(readValue(dataType));
if (j < numFields - 1)
s.append(", ");
}
value = s.toString();
} else if (dataType == GROUP) {
// this is an array of structs
skipPadding();
dataType = in.readInt();
if (dataType == ARRAY) {
// should always be true
in.skipBytes(4);
skipPadding();
skipPadding();
int numFields = in.readInt();
int[] dataTypes = new int[numFields];
long baseFP = in.getFilePointer() + 12;
for (int j = 0; j < numFields; j++) {
in.skipBytes(4);
if (version == 4) {
in.seek(baseFP + j * 16);
}
dataTypes[j] = in.readInt();
}
skipPadding();
int len = in.readInt();
double[][] values = new double[numFields][len];
for (int k = 0; k < len; k++) {
for (int q = 0; q < numFields; q++) {
values[q][k] = readValue(dataTypes[q]);
}
}
} else
LOGGER.warn("dataType mismatch: {}", dataType);
}
}
} else if (type == GROUP) {
labelString = in.readByteToString(length);
in.skipBytes(2);
skipPadding();
skipPadding();
skipPadding();
int num = in.readInt();
LOGGER.debug("{}{}: group({}) {} {", new Object[] { indent, i, num, labelString });
parseTags(num, labelString.isEmpty() ? parent : labelString, indent + " ");
LOGGER.debug("{}}", indent);
} else {
LOGGER.debug("{}{}: unknown type: {}", new Object[] { indent, i, type });
}
NumberFormat f = NumberFormat.getInstance(Locale.ENGLISH);
if (value != null) {
addGlobalMeta(labelString, value);
if (parent != null && parent.equals("AnnotationGroupList")) {
// ROI found
ROIShape shape = new ROIShape();
if (labelString.equals("AnnotationType")) {
shape.type = DataTools.parseDouble(value).intValue();
shapes.add(shape);
} else if (shapes.size() > 0) {
shape = shapes.get(shapes.size() - 1);
}
if (labelString.equals("Rectangle")) {
String[] points = value.split(",");
shape.y1 = DataTools.parseDouble(points[0].trim());
shape.x1 = DataTools.parseDouble(points[1].trim());
shape.y2 = DataTools.parseDouble(points[2].trim());
shape.x2 = DataTools.parseDouble(points[3].trim());
} else if (labelString.equals("Text")) {
shape.text = value;
} else if (labelString.equals("ForegroundColor")) {
String[] colors = value.split(",");
int red = DataTools.parseDouble(colors[0].trim()).intValue() & 0xff;
int green = DataTools.parseDouble(colors[1].trim()).intValue() & 0xff;
int blue = DataTools.parseDouble(colors[2].trim()).intValue() & 0xff;
shape.strokeColor = new Color(red, green, blue, 255);
}
} else if (parent != null && parent.equals("TextFormat")) {
if (labelString.equals("FontSize")) {
ROIShape shape = shapes.get(shapes.size() - 1);
shape.fontSize = FormatTools.getFontSize(DataTools.parseDouble(value).intValue());
}
}
boolean validPhysicalSize = parent != null && (parent.equals("Dimension") || ((pixelSizes.size() == 4 || units.size() == 4) && parent.equals("2")));
if (labelString.equals("Scale") && validPhysicalSize) {
if (value.indexOf(',') == -1) {
pixelSizes.add(f.parse(value).doubleValue());
}
} else if (labelString.equals("Units") && validPhysicalSize) {
// make sure that we don't add more units than sizes
if (pixelSizes.size() == units.size() + 1) {
units.add(value);
}
} else if (labelString.equals("LowLimit")) {
signed = f.parse(value).doubleValue() < 0;
} else if (labelString.equals("Acquisition Start Time (epoch)")) {
timestamp = f.parse(value).longValue();
} else if (labelString.equals("Voltage")) {
voltage = f.parse(value).doubleValue();
} else if (labelString.equals("Microscope Info"))
info = value;
else if (labelString.equals("Indicated Magnification")) {
mag = f.parse(value).doubleValue();
} else if (labelString.equals("Gamma")) {
gamma = f.parse(value).doubleValue();
} else if (labelString.startsWith("xPos")) {
final Double number = f.parse(value).doubleValue();
posX = new Length(number, UNITS.REFERENCEFRAME);
} else if (labelString.startsWith("yPos")) {
final Double number = f.parse(value).doubleValue();
posY = new Length(number, UNITS.REFERENCEFRAME);
} else if (labelString.startsWith("Specimen position")) {
final Double number = f.parse(value).doubleValue();
posZ = new Length(number, UNITS.REFERENCEFRAME);
} else if (labelString.equals("Sample Time")) {
sampleTime = f.parse(value).doubleValue();
} else if (labelString.equals("DataType")) {
int pixelType = f.parse(value).intValue();
switch(pixelType) {
case 1:
core.get(0).pixelType = FormatTools.INT16;
break;
case 10:
core.get(0).pixelType = FormatTools.UINT16;
break;
case 2:
core.get(0).pixelType = FormatTools.FLOAT;
break;
case 12:
core.get(0).pixelType = FormatTools.DOUBLE;
break;
case 9:
core.get(0).pixelType = FormatTools.INT8;
break;
case 6:
core.get(0).pixelType = FormatTools.UINT8;
break;
case 7:
core.get(0).pixelType = FormatTools.INT32;
break;
case 11:
core.get(0).pixelType = FormatTools.UINT32;
}
}
value = null;
}
}
}
use of ome.xml.model.primitives.Color in project bioformats by openmicroscopy.
the class ImprovisionTiffReader method initStandardMetadata.
// -- Internal BaseTiffReader API methods --
/* @see BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
super.initStandardMetadata();
put("Improvision", "yes");
// parse key/value pairs in the comments
String[] comments = new String[ifds.size()];
String tz = null, tc = null, tt = null;
for (int plane = 0; plane < ifds.size(); plane++) {
String comment = ifds.get(plane).getComment();
comments[plane] = comment;
if (comment != null) {
String[] lines = comment.split("\n");
for (String line : lines) {
int equals = line.indexOf('=');
if (equals < 0)
continue;
String key = line.substring(0, equals);
String value = line.substring(equals + 1);
addGlobalMeta(key, value);
if (key.equals("TotalZPlanes"))
tz = value;
else if (key.equals("TotalChannels"))
tc = value;
else if (key.equals("TotalTimepoints"))
tt = value;
else if (key.equals("XCalibrationMicrons")) {
pixelSizeX = DataTools.parseDouble(value);
} else if (key.equals("YCalibrationMicrons")) {
pixelSizeY = DataTools.parseDouble(value);
} else if (key.equals("ZCalibrationMicrons")) {
pixelSizeZ = DataTools.parseDouble(value);
} else if (key.equals("WhiteColour")) {
String[] rgb = value.split(",");
if (rgb.length < 3) {
channelColors.add(null);
continue;
}
int red = 255;
try {
red = Integer.parseInt(rgb[0]);
} catch (NumberFormatException e) {
}
int green = 255;
try {
green = Integer.parseInt(rgb[1]);
} catch (NumberFormatException e) {
}
int blue = 255;
try {
blue = Integer.parseInt(rgb[2]);
} catch (NumberFormatException e) {
}
channelColors.add(new Color(red, green, blue, 255));
}
}
metadata.remove("Comment");
}
}
CoreMetadata m = core.get(0);
m.sizeT = 1;
if (getSizeZ() == 0)
m.sizeZ = 1;
if (getSizeC() == 0)
m.sizeC = 1;
if (tz != null)
m.sizeZ *= Integer.parseInt(tz);
if (tc != null)
m.sizeC *= Integer.parseInt(tc);
if (tt != null)
m.sizeT *= Integer.parseInt(tt);
if (getSizeZ() * getSizeC() * getSizeT() < getImageCount()) {
m.sizeC *= getImageCount();
} else
m.imageCount = getSizeZ() * getSizeT() * Integer.parseInt(tc);
// parse each of the comments to determine axis ordering
long[] stamps = new long[ifds.size()];
int[][] coords = new int[ifds.size()][3];
cNames = new String[getSizeC()];
boolean multipleFiles = false;
for (int i = 0; i < ifds.size(); i++) {
Arrays.fill(coords[i], -1);
String comment = comments[i];
// TODO : can use loci.common.IniParser to parse the comments
comment = comment.replaceAll("\r\n", "\n");
comment = comment.replaceAll("\r", "\n");
String channelName = null;
String[] lines = comment.split("\n");
for (String line : lines) {
int equals = line.indexOf('=');
if (equals < 0)
continue;
String key = line.substring(0, equals);
String value = line.substring(equals + 1);
if (key.equals("TimeStampMicroSeconds")) {
stamps[i] = Long.parseLong(value);
} else if (key.equals("ZPlane"))
coords[i][0] = Integer.parseInt(value);
else if (key.equals("ChannelNo")) {
coords[i][1] = Integer.parseInt(value);
int ndx = Integer.parseInt(value) - 1;
if (cNames[ndx] == null)
cNames[ndx] = channelName;
} else if (key.equals("TimepointName")) {
coords[i][2] = Integer.parseInt(value);
} else if (key.equals("ChannelName")) {
channelName = value;
} else if (key.equals("MultiFileTIFF")) {
multipleFiles = value.equalsIgnoreCase("yes");
}
if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM && coords[i][0] >= 0 && coords[i][1] >= 0 && coords[i][2] >= 0) {
break;
}
}
}
if (multipleFiles) {
// look for other TIFF files that belong to this dataset
String currentUUID = getUUID(currentId);
Location parent = new Location(currentId).getAbsoluteFile().getParentFile();
String[] list = parent.list(true);
Arrays.sort(list);
ArrayList<String> matchingFiles = new ArrayList<String>();
for (String f : list) {
String path = new Location(parent, f).getAbsolutePath();
if (isThisType(path) && getUUID(path).equals(currentUUID)) {
matchingFiles.add(path);
}
}
files = matchingFiles.toArray(new String[matchingFiles.size()]);
} else {
files = new String[] { currentId };
}
if (files.length * ifds.size() < getImageCount()) {
files = new String[] { currentId };
m.imageCount = ifds.size();
m.sizeZ = ifds.size();
m.sizeT = 1;
if (!isRGB()) {
m.sizeC = 1;
}
}
readers = new MinimalTiffReader[files.length];
for (int i = 0; i < readers.length; i++) {
readers[i] = new MinimalTiffReader();
readers[i].setId(files[i]);
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
// determine average time per plane
long sum = 0;
for (int i = 1; i < stamps.length; i++) {
long diff = stamps[i] - stamps[i - 1];
if (diff > 0)
sum += diff;
}
pixelSizeT = (int) (sum / getSizeT());
}
// determine dimension order
m.dimensionOrder = "XY";
if (isRGB())
m.dimensionOrder += 'C';
for (int i = 1; i < coords.length; i++) {
int zDiff = coords[i][0] - coords[i - 1][0];
int cDiff = coords[i][1] - coords[i - 1][1];
int tDiff = coords[i][2] - coords[i - 1][2];
if (zDiff > 0 && getDimensionOrder().indexOf('Z') < 0) {
m.dimensionOrder += 'Z';
}
if (cDiff > 0 && getDimensionOrder().indexOf('C') < 0) {
m.dimensionOrder += 'C';
}
if (tDiff > 0 && getDimensionOrder().indexOf('T') < 0) {
m.dimensionOrder += 'T';
}
if (m.dimensionOrder.length() == 5)
break;
}
if (getDimensionOrder().indexOf('Z') < 0)
m.dimensionOrder += 'Z';
if (getDimensionOrder().indexOf('C') < 0)
m.dimensionOrder += 'C';
if (getDimensionOrder().indexOf('T') < 0)
m.dimensionOrder += 'T';
}
use of ome.xml.model.primitives.Color 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 ome.xml.model.primitives.Color in project bioformats by openmicroscopy.
the class BaseZeissReader method fillMetadataPass7.
/**
* Store basic dimensions in model
* @param store
* @throws FormatException
* @throws IOException
*/
protected void fillMetadataPass7(MetadataStore store) throws FormatException, IOException {
for (int i = 0; i < getSeriesCount(); i++) {
long firstStamp = 0;
if (timestamps.size() > 0) {
String timestamp = timestamps.get(0);
store.setImageAcquisitionDate(new Timestamp(timestamp), i);
} else if (acquisitionDate != null) {
store.setImageAcquisitionDate(acquisitionDate, i);
}
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
// link Instrument and Image
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
store.setObjectiveID(objectiveID, 0, 0);
store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
Integer[] channelKeys = channelName.keySet().toArray(new Integer[channelName.size()]);
Arrays.sort(channelKeys);
// link DetectorSettings to an actual Detector
for (int i = 0; i < getEffectiveSizeC(); i++) {
String detectorID = MetadataTools.createLSID("Detector", 0, i);
store.setDetectorID(detectorID, 0, i);
store.setDetectorType(getDetectorType("Other"), 0, i);
for (int s = 0; s < getSeriesCount(); s++) {
int c = i;
if (i < channelKeys.length) {
c = channelKeys[i];
}
store.setDetectorSettingsID(detectorID, s, i);
store.setDetectorSettingsGain(detectorGain.get(c), s, i);
store.setDetectorSettingsOffset(detectorOffset.get(c), s, i);
store.setChannelName(channelName.get(c), s, i);
store.setChannelEmissionWavelength(emWavelength.get(c), s, i);
store.setChannelExcitationWavelength(exWavelength.get(c), s, i);
if (channelColors != null && i < channelColors.length) {
int color = channelColors[i];
int red = color & 0xff;
int green = (color & 0xff00) >> 8;
int blue = (color & 0xff0000) >> 16;
store.setChannelColor(new Color(red, green, blue, 255), s, i);
}
}
}
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageInstrumentRef(instrumentID, i);
store.setObjectiveSettingsID(objectiveID, i);
if (imageDescription != null) {
store.setImageDescription(imageDescription, i);
}
if (getSeriesCount() > 1) {
store.setImageName("Tile #" + (i + 1), i);
}
Length sizeX = FormatTools.getPhysicalSizeX(physicalSizeX);
Length sizeY = FormatTools.getPhysicalSizeY(physicalSizeY);
Length sizeZ = FormatTools.getPhysicalSizeZ(physicalSizeZ);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, i);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, i);
}
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, i);
}
Timestamp firstStamp = null;
if (timestamps.get(0) != null) {
firstStamp = new Timestamp(timestamps.get(0));
}
for (int plane = 0; plane < getImageCount(); plane++) {
int[] zct = getZCTCoords(plane);
int expIndex = zct[1];
if (channelKeys.length > 0) {
expIndex += channelKeys[0];
}
String exposure = exposureTime.get(expIndex);
if (exposure == null && exposureTime.size() == 1) {
exposure = exposureTime.values().iterator().next();
}
Double exp = 0d;
try {
exp = new Double(exposure);
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
}
store.setPlaneExposureTime(new Time(exp, UNITS.SECOND), i, plane);
int posIndex = i * getImageCount() + plane;
if (posIndex < timestamps.size() && firstStamp != null) {
Timestamp timestamp = new Timestamp(timestamps.get(posIndex));
long difference = timestamp.asInstant().getMillis() - firstStamp.asInstant().getMillis();
double delta = (double) difference;
store.setPlaneDeltaT(new Time(delta, UNITS.MILLISECOND), i, plane);
}
if (stageX.get(posIndex) != null) {
store.setPlanePositionX(stageX.get(posIndex), i, plane);
}
if (stageY.get(posIndex) != null) {
store.setPlanePositionY(stageY.get(posIndex), i, plane);
}
}
}
for (int i = 0; i < getSeriesCount(); i++) {
for (int roi = 0; roi < roiIDs.size(); roi++) {
store.setImageROIRef(roiIDs.get(roi), i, roi);
}
}
}
}
Aggregations