Skip to content

Commit

Permalink
Added more sophisticated image name parsing to OpenlabReader. Closes #…
Browse files Browse the repository at this point in the history
…615, closes #616.
  • Loading branch information
melissalinkert committed Dec 9, 2010
1 parent d19cfcf commit 316ee88
Showing 1 changed file with 77 additions and 13 deletions.
90 changes: 77 additions & 13 deletions components/bio-formats/src/loci/formats/in/OpenlabReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class OpenlabReader extends FormatReader {
private int lastPlane;

private String gain, detectorOffset, xPos, yPos, zPos;
private boolean specialPlateNames = false;

// -- Constructor --

Expand Down Expand Up @@ -141,18 +142,23 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)

lastPlane = no;

if (no >= planeOffsets[series].length) return buf;
int index = planeOffsets[series][no];
PlaneInfo planeInfo = null;
if (specialPlateNames) {
planeInfo = getPlane(getZCTCoords(no));
}
else if (no < planeOffsets[series].length) {
int index = planeOffsets[series][no];
planeInfo = planes[index];
}
if (planeInfo == null) return buf;

long first = planes[index].planeOffset;
long last = no == planeOffsets[series].length - 1 ||
planeOffsets[series][no + 1] >= planes.length ? in.length() :
planes[planeOffsets[series][no + 1]].planeOffset;
long first = planeInfo.planeOffset;
long last = first + FormatTools.getPlaneSize(this) * 2;
in.seek(first);

int bpp = FormatTools.getBytesPerPixel(getPixelType());

if (!planes[index].pict) {
if (!planeInfo.pict) {
if (version == 2) {
readPlane(in, x, y, w, h, buf);
}
Expand Down Expand Up @@ -187,8 +193,8 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
}
b = null;
}
if (planes[index].volumeType == MAC_256_GREYS ||
planes[index].volumeType == MAC_256_COLORS)
if (planeInfo.volumeType == MAC_256_GREYS ||
planeInfo.volumeType == MAC_256_COLORS)
{
for (int i=0; i<buf.length; i++) {
buf[i] = (byte) (~buf[i] & 0xff);
Expand Down Expand Up @@ -228,7 +234,7 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
if (exc != null) {
r.close();
LOGGER.debug("", exc);
in.seek(planes[index].planeOffset - 298);
in.seek(planeInfo.planeOffset - 298);

if (in.readByte() == 1) in.skipBytes(128);
in.skipBytes(169);
Expand Down Expand Up @@ -297,6 +303,7 @@ public void close(boolean fileOnly) throws IOException {
planeOffsets = null;
gain = detectorOffset = null;
xPos = yPos = zPos = null;
specialPlateNames = false;
}
}

Expand Down Expand Up @@ -683,9 +690,44 @@ private void parseImageNames(int s) {

core[s].dimensionOrder = "XY";
for (PlaneInfo plane : planes) {
if (plane == null) continue;
if (plane.series == s) {
String name = plane.planeName;
if (plane == null || plane.series != s) continue;

String name = plane.planeName;

// check for a specific name format:
// <channel name><optional timepoint>_<plate>_<well>_<Z section>

String[] tokens = name.split("_");
if (tokens.length == 4) {
specialPlateNames = true;

if (!uniqueZ.contains(tokens[3])) {
uniqueZ.add(tokens[3]);
}
plane.channelName = tokens[0];
int endIndex = 0;
while (endIndex < plane.channelName.length() &&
!Character.isDigit(plane.channelName.charAt(endIndex)))
{
endIndex++;
}
String timepoint = plane.channelName.substring(endIndex);
if (timepoint.equals("")) timepoint = "1";
plane.channelName = plane.channelName.substring(0, endIndex);

if (!uniqueC.contains(plane.channelName)) {
uniqueC.add(plane.channelName);
}
if (!uniqueT.contains(timepoint)) {
uniqueT.add(timepoint);
}

core[s].dimensionOrder = "XYCTZ";
plane.wavelength = uniqueC.indexOf(plane.channelName);
plane.timepoint = uniqueT.indexOf(timepoint);
plane.zPosition = uniqueZ.indexOf(tokens[3]);
}
else {
for (String axis : axes) {
Vector<String> unique = null;
if (axis.equals("Z")) unique = uniqueZ;
Expand Down Expand Up @@ -716,6 +758,14 @@ private void parseImageNames(int s) {
}
}

if (specialPlateNames) {
core[s].sizeC *= uniqueC.size();
core[s].sizeT = uniqueT.size();
core[s].sizeZ = uniqueZ.size();
core[s].imageCount = core[s].sizeC * core[s].sizeZ * core[s].sizeT;
return;
}

if (core[s].rgb && uniqueC.size() <= 1) {
core[s].dimensionOrder = core[s].dimensionOrder.replaceAll("C", "");
core[s].dimensionOrder = "XYC" + core[s].dimensionOrder.substring(2);
Expand Down Expand Up @@ -749,13 +799,26 @@ private void parseImageNames(int s) {
else if (newCount > getImageCount()) core[s].imageCount = newCount;
}

private PlaneInfo getPlane(int[] zct) {
for (PlaneInfo plane : planes) {
if (plane != null && plane.zPosition == zct[0] &&
plane.wavelength == zct[1] && plane.timepoint == zct[2] &&
plane.series == getSeries())
{
return plane;
}
}
return null;
}

// -- Helper classes --

/** Helper class for storing plane info. */
protected class PlaneInfo {
protected long planeOffset;
protected int zPosition;
protected int wavelength;
protected int timepoint;
protected String planeName;
protected long timestamp;
protected boolean pict;
Expand All @@ -764,6 +827,7 @@ protected class PlaneInfo {
protected int width;
protected int height;
protected int series = -1;
protected String channelName;
}

}

0 comments on commit 316ee88

Please sign in to comment.