Skip to content

Commit

Permalink
Only allow merging if there are 2 or 3 channels; otherwise display a …
Browse files Browse the repository at this point in the history
…warning (and the grayscale stack).
  • Loading branch information
melissalinkert committed Mar 15, 2007
1 parent 67a0498 commit c21ddb6
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions loci/plugins/Importer.java
Expand Up @@ -1138,7 +1138,7 @@ private void displayStack(ImagePlus imp, IFormatReader r,
try {
// convert to RGB if needed

if (mergeChannels && r.getSizeC(id) > 1) {
if (mergeChannels && r.getSizeC(id) > 1 && r.getSizeC(id) < 4) {
int c = r.getSizeC(id);
ImageStack s = imp.getStack();
ImageStack newStack = new ImageStack(s.getWidth(), s.getHeight());
Expand All @@ -1155,31 +1155,26 @@ private void displayStack(ImagePlus imp, IFormatReader r,
int sizeZ = r.getSizeZ(id);
int sizeT = r.getSizeT(id);

int extraC = 1;
if (c > 4) {
extraC *= (c % 3 == 0 ? 4 : 3);
c /= extraC;
}

for (int z=0; z<sizeZ; z++) {
for (int t=0; t<sizeT; t++) {
byte[][] bytes = new byte[c][];
for (int ch1=0; ch1<extraC; ch1++) {
for (int ch2=0; ch2<c; ch2++) {
int ndx = r.getIndex(id, z, ch1*c + ch2, t) + 1;
bytes[ch2] = (byte[]) s.getProcessor(ndx).getPixels();
}
ColorProcessor cp =
new ColorProcessor(s.getWidth(), s.getHeight());
cp.setRGB(bytes[0], bytes[1], bytes.length == 3 ? bytes[2] :
new byte[s.getWidth() * s.getHeight()]);
int ndx = r.getIndex(id, z, ch1*c + c - 1, t) + 1;
newStack.addSlice(s.getSliceLabel(ndx), cp);
for (int ch1=0; ch1<c; ch1++) {
int ndx = r.getIndex(id, z, ch1, t) + 1;
bytes[ch1] = (byte[]) s.getProcessor(ndx).getPixels();
}
ColorProcessor cp =
new ColorProcessor(s.getWidth(), s.getHeight());
cp.setRGB(bytes[0], bytes[1], bytes.length == 3 ? bytes[2] :
new byte[s.getWidth() * s.getHeight()]);
int ndx = r.getIndex(id, z, c - 1, t) + 1;
newStack.addSlice(s.getSliceLabel(ndx), cp);
}
}
imp.setStack(imp.getTitle(), newStack);
}
else if (mergeChannels && r.getSizeC(id) >= 4) {
IJ.showMessage("Can only merge 2 or 3 channels.");
}

imp.setDimensions(
imp.getStackSize() / (imp.getNSlices() * imp.getNFrames()),
Expand Down

0 comments on commit c21ddb6

Please sign in to comment.