ImgPlus with 3 channels is wrongly displayed as RGB (imglib2)

Hello,

I find some inconsistencies when displaying ImgPlus. Three channels are displayed as a RGB image in imageJ, 4 channels are displayed correctly. How can we force the display not to use RGB?
Here is a code that shows the described behaviour

Greetings

Antonio


import io.scif.img.ImgIOException;
import net.imagej.ImageJ;
import net.imagej.ImgPlus;
import net.imagej.axis.Axes;
import net.imagej.axis.AxisType;
import net.imglib2.img.array.ArrayImgs;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import org.apache.commons.io.FilenameUtils;

public class wrongDisplayRGB {
    public static void main( final String[] args ) throws ImgIOException {
        ImgPlus<UnsignedByteType> ch3 = new ImgPlus(ArrayImgs.unsignedBytes(100, 100, 100, 3),
                "3 channels -> RGB?",
                new AxisType[] {Axes.X, Axes.Y, Axes.Z, Axes.CHANNEL});
        ImgPlus<UnsignedByteType> ch4 = new ImgPlus(ArrayImgs.unsignedBytes(100, 100, 100, 4),
                "4 channels",
                new AxisType[] {Axes.X, Axes.Y, Axes.Z, Axes.CHANNEL});
        ImageJ ij;
        ij = new ImageJ();
        ij.ui().showUI();
        ij.ui().show(ch3); // shown as RGB
        ij.ui().show(ch4); // shown as 4 channel image
    }
}

1 Like

Generated an issue on GitHub https://github.com/imglib/imglib2/issues/275

2 Likes

I guess this is a feature of the ImageJ1 backwards compatibility. (@maarzt might know with more certainty, but he is on leave right now.)

If you wrap the ImgPlus into ImageJ2’s primary data structure Dataset first, you can toggle this behavior:

Dataset d3 = ij.dataset().create(ch3);
d3.setRGBMerged(false);
ij.ui().show(d3); // will show with separate channels
3 Likes