Composite image channel color

Hi @Wayne,

I have a question about CompositeImage. It has below method:

	public Color getChannelColor() {
		if (lut==null || mode==GRAYSCALE)
			return Color.black;
		IndexColorModel cm = lut[getChannelIndex()];
		if (cm==null)
			return Color.black;
		int index = cm.getMapSize() - 1;
		int r = cm.getRed(index);
		int g = cm.getGreen(index);
		int b = cm.getBlue(index);
		//IJ.log(index+" "+r+" "+g+" "+b);
		if (r<100 || g<100 || b<100)
			return new Color(r, g, b);
		else
			return Color.black;
	}

Could you explain what the point of the if (r<100 || g<100 || b<100) is?

Thank you very much!

The CompositeImage.getChannelColor() method returns the color used to display the image subtitle and ā€œB&Cā€ histogram (see screenshot). The if (r<100 || g<100 || b<100) is intended to avoid returning colors that are too bright.

2 Likes

@Wayne
Thank you for the answer! For my application I need the channel color in order to save it for some other file format (i.e., Imaris). I appreciate that in general there is no such thing as a simple channel color, because it is a LUT. Anyway, I used your code for inspiration and came up with a solution that I paste below in case someone else find it useful:

        for ( int c = 0; c < imp.getNChannels(); ++c )
        {
            if ( imp instanceof CompositeImage )
            {
                CompositeImage compositeImage = ( CompositeImage ) imp;
				LUT channelLut = compositeImage.getChannelLut( c + 1 );
				int mode = compositeImage.getMode();
				if ( channelLut == null || mode == GRAYSCALE )
				{
					channelColors.add( ImarisUtils.DEFAULT_COLOR );
				}
				else
				{
					IndexColorModel cm = channelLut.getColorModel();
					if ( cm == null )
					{
						channelColors.add( ImarisUtils.DEFAULT_COLOR );
					}
					else
					{
						int i = cm.getMapSize() - 1;
						String color = "" + cm.getRed( i ) / 255.0 + " " + cm.getGreen( i ) / 255.0 + " " + cm.getBlue( i ) / 255.0;
						channelColors.add( color );
					}

				}

				compositeImage.setC( c + 1 );
                channelRanges.add( "" + compositeImage.getDisplayRangeMin() + " " +  compositeImage.getDisplayRangeMax() );
                channelNames.add( "channel_" + c );
            }
            else
            {
                channelColors.add( ImarisUtils.DEFAULT_COLOR );
                channelRanges.add( "" + imp.getDisplayRangeMin() + " " +  imp.getDisplayRangeMax() );
                channelNames.add( "channel_" + c );
            }
        }
    }