Skip to content

Commit

Permalink
Move X, Y, and Z channels from start to end
Browse files Browse the repository at this point in the history
The channels labeled X, Y, and Z appear to be calibration of some kind,
but are stored with the rest of the raw data. These 3 channels appear
first in the file, but we want them to appear last after conversion
so that thumbnails in OMERO reflect real data.
  • Loading branch information
melissalinkert committed Oct 4, 2023
1 parent c38954b commit c6f46dc
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions src/main/java/com/glencoesoftware/bioformats2raw/MCDReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
// channels are stored interleaved, so reading requires
// a lot of skipping through the pixel data block

in.skipBytes(bpp * no);
in.skipBytes(bpp * getReversePlaneIndex(no));
int skip = bpp * (getImageCount() - 1);

in.skipBytes(y * (skip + bpp) * getSizeX());
Expand Down Expand Up @@ -258,6 +258,8 @@ protected void initFile(String id) throws FormatException, IOException {
}
for (int a=0; a<acquisitions.size(); a++) {
int imageIndex = a + panoramas.size();
setSeries(imageIndex);

Acquisition acq = acquisitions.get(a);
store.setImageName(acq.description, imageIndex);

Expand All @@ -267,10 +269,12 @@ protected void initFile(String id) throws FormatException, IOException {
// this is kind of wrong, but the reference viewer
// exposes both the name and label (which are often slightly different)
// and this is the easiest way to do that in OME/OMERO model
store.setChannelName(channel.name, imageIndex, c);
store.setChannelFluor(channel.label, imageIndex, c);
int channelIndex = getPlaneIndex(c);
store.setChannelName(channel.name, imageIndex, channelIndex);
store.setChannelFluor(channel.label, imageIndex, channelIndex);
}
}
setSeries(0);
}

// -- Helper methods --
Expand Down Expand Up @@ -307,6 +311,41 @@ private static String readString(RandomAccessInputStream s)
return s.readString(len);
}

/**
* Calculate internal plane index.
* Allows moving the XYZ channels to the end of the channel list.
*
* @param no original plane index
* @return adjusted plane index
*/
private int getPlaneIndex(int no) {
if (getImageCount() <= 3) {
return no;
}
if (no < 3) {
return (getImageCount() - 3) + no;
}
return no - 3;
}

/**
* Calculate internal plane index.
* Allows moving the XYZ channels to the end of the channel list.
*
* @param no original plane index
* @return adjusted plane index
*/
private int getReversePlaneIndex(int no) {
if (getImageCount() <= 3) {
return no;
}
int threshold = getImageCount() - 3;
if (no < threshold) {
return no + 3;
}
return no - threshold;
}

// -- Helper class --

class MCDHandler extends BaseHandler {
Expand Down

0 comments on commit c6f46dc

Please sign in to comment.