use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class MIASReader method getChannelColorFromFile.
// -- Helper methods --
/**
* Get the color associated with the given file's channel.
* The file must be one of the
* Well<nnnn>_mode<n>_z<nnn>_t<nnn>_AllModesOverlay.tif
* files in <experiment>/<plate>/results/
*/
private Color getChannelColorFromFile(String file) throws FormatException, IOException {
RandomAccessInputStream s = new RandomAccessInputStream(file, 16);
TiffParser tp = new TiffParser(s);
IFD ifd = tp.getFirstIFD();
s.close();
if (ifd == null)
return null;
int[] colorMap = tp.getColorMap(ifd);
if (colorMap == null)
return null;
int nEntries = colorMap.length / 3;
int max = Integer.MIN_VALUE;
int maxIndex = -1;
for (int c = 0; c < 3; c++) {
int v = (colorMap[c * nEntries] >> 8) & 0xff;
if (v > max) {
max = v;
maxIndex = c;
} else if (v == max) {
return new Color(0, 0, 0, 255);
}
}
switch(maxIndex) {
case // red
0:
return new Color(255, 0, 0, 255);
case // green
1:
return new Color(0, 255, 0, 255);
case // blue
2:
return new Color(0, 0, 255, 255);
}
return null;
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class IPWReader method getOptimalTileHeight.
/* @see loci.formats.IFormatReader#getOptimalTileHeight() */
@Override
public int getOptimalTileHeight() {
FormatTools.assertId(currentId, true, 1);
try {
RandomAccessInputStream stream = poi.getDocumentStream(imageFiles.get(0));
TiffParser tp = new TiffParser(stream);
IFD ifd = tp.getFirstIFD();
stream.close();
return (int) ifd.getTileLength();
} catch (FormatException e) {
LOGGER.debug("Could not retrieve tile height", e);
} catch (IOException e) {
LOGGER.debug("Could not retrieve tile length", e);
}
return super.getOptimalTileHeight();
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class IPWReader 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);
initPOIService();
imageFiles = new HashMap<Integer, String>();
Vector<String> fileList = poi.getDocumentList();
String description = null, creationDate = null;
CoreMetadata m = core.get(0);
for (String name : fileList) {
String relativePath = name.substring(name.lastIndexOf(File.separator) + 1);
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
if (relativePath.equals("CONTENTS")) {
addGlobalMeta("Version", new String(poi.getDocumentBytes(name), Constants.ENCODING).trim());
} else if (relativePath.equals("FrameRate")) {
byte[] b = poi.getDocumentBytes(name, 4);
addGlobalMeta("Frame Rate", DataTools.bytesToInt(b, true));
} else if (relativePath.equals("FrameInfo")) {
RandomAccessInputStream s = poi.getDocumentStream(name);
s.order(true);
for (int q = 0; q < s.length() / 2; q++) {
addGlobalMetaList("FrameInfo", s.readShort());
}
s.close();
}
}
if (relativePath.equals("ImageInfo")) {
description = new String(poi.getDocumentBytes(name), Constants.ENCODING).trim();
addGlobalMeta("Image Description", description);
String timestamp = null;
// basically the same as in SEQReader
if (description != null) {
String[] tokens = description.split("\n");
for (String token : tokens) {
String label = "Timestamp";
String data = token.trim();
if (token.indexOf('=') != -1) {
label = token.substring(0, token.indexOf('=')).trim();
data = token.substring(token.indexOf('=') + 1).trim();
}
addGlobalMeta(label, data);
if (label.equals("frames"))
m.sizeT = Integer.parseInt(data);
else if (label.equals("slices")) {
m.sizeZ = Integer.parseInt(data);
} else if (label.equals("channels")) {
m.sizeC = Integer.parseInt(data);
} else if (label.equals("Timestamp"))
timestamp = data;
}
}
if (timestamp != null) {
if (timestamp.length() > 26) {
timestamp = timestamp.substring(timestamp.length() - 26);
}
creationDate = DateTools.formatDate(timestamp, "MM/dd/yyyy HH:mm:ss aa", ".");
}
} else if (relativePath.equals("ImageTIFF")) {
// pixel data
String idx = "0";
if (!name.substring(0, name.lastIndexOf(File.separator)).equals("Root Entry")) {
idx = name.substring(21, name.indexOf(File.separator, 22));
}
imageFiles.put(new Integer(idx), name);
}
}
LOGGER.info("Populating metadata");
m.imageCount = imageFiles.size();
RandomAccessInputStream stream = poi.getDocumentStream(imageFiles.get(0));
TiffParser tp = new TiffParser(stream);
IFD firstIFD = tp.getFirstIFD();
stream.close();
m.rgb = firstIFD.getSamplesPerPixel() > 1;
if (!isRGB()) {
m.indexed = firstIFD.getPhotometricInterpretation() == PhotoInterp.RGB_PALETTE;
}
if (isIndexed()) {
m.sizeC = 1;
m.rgb = false;
}
m.littleEndian = firstIFD.isLittleEndian();
// retrieve axis sizes
addGlobalMeta("slices", "1");
addGlobalMeta("channels", "1");
addGlobalMeta("frames", getImageCount());
m.sizeX = (int) firstIFD.getImageWidth();
m.sizeY = (int) firstIFD.getImageLength();
m.dimensionOrder = isRGB() ? "XYCZT" : "XYZCT";
if (getSizeZ() == 0)
m.sizeZ = 1;
if (getSizeC() == 0)
m.sizeC = 1;
if (getSizeT() == 0)
m.sizeT = 1;
if (getSizeZ() * getSizeC() * getSizeT() == 1 && getImageCount() != 1) {
m.sizeZ = getImageCount();
}
if (isRGB())
m.sizeC *= 3;
int bitsPerSample = firstIFD.getBitsPerSample()[0];
m.pixelType = firstIFD.getPixelType();
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
store.setImageDescription(description, 0);
if (creationDate != null) {
store.setImageAcquisitionDate(new Timestamp(creationDate), 0);
}
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class ImprovisionTiffReader method getUUID.
// -- Helper methods --
private String getUUID(String path) throws FormatException, IOException {
RandomAccessInputStream s = new RandomAccessInputStream(path, 16);
TiffParser parser = new TiffParser(s);
String comment = parser.getComment();
s.close();
comment = comment.replaceAll("\r\n", "\n");
comment = comment.replaceAll("\r", "\n");
String[] lines = comment.split("\n");
for (String line : lines) {
line = line.trim();
if (line.startsWith("SampleUUID=")) {
return line.substring(line.indexOf('=') + 1).trim();
}
}
return "";
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class SISReader 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);
String make = ifd.getIFDTextValue(IFD.MAKE);
return (ifd.get(SIS_TAG) != null && (software == null || software.startsWith("analySIS"))) || (ifd.get(SIS_TAG_2) != null && (make != null && make.startsWith("Olympus")));
}
Aggregations