Class RGBToGrayConversion


  • public class RGBToGrayConversion
    extends ImageToImageOperation
    Converts RGB color images (both truecolor and paletted) to grayscale images. The weights to be used with the three base colors red, green and blue can be modified with a call to setColorWeights(float, float, float).

    Supported image types

    RGB24Image and Paletted8Image can be used as input image types. A Gray8Image be will be created from them.

    Could be optimized to use int multiplication instead of float multiplication.

    Usage example

    Convert some PixelImage rgbImage to grayscale:
    PixelImage grayImg = RGBToGrayConversion.convert(rgbImage);
    Using your own color weights can be done like this. You may also want to specify an output grayscale image if you have one to reuse.
     RGBToGrayConversion rgbtogray = new RGBToGrayConversion();
     rgbtogray.setInputImage(image);
     rgbtogray.setColorWeights(0.3f, 0.3f, 0.4f);
     rgbtogray.process();
     PixelImage grayImage = rgbtogray.getOutputImage();
     
    Author:
    Marco Schmidt
    • Field Detail

      • DEFAULT_RED_WEIGHT

        public static final float DEFAULT_RED_WEIGHT
        The default weight for red samples in the conversion, 0.3f.
        See Also:
        Constant Field Values
      • DEFAULT_GREEN_WEIGHT

        public static final float DEFAULT_GREEN_WEIGHT
        The default weight for green samples in the conversion, 0.59f.
        See Also:
        Constant Field Values
      • DEFAULT_BLUE_WEIGHT

        public static final float DEFAULT_BLUE_WEIGHT
        The default weight for blue samples in the conversion, 0.11f.
        See Also:
        Constant Field Values
      • redWeight

        private float redWeight
      • greenWeight

        private float greenWeight
      • blueWeight

        private float blueWeight
    • Constructor Detail

      • RGBToGrayConversion

        public RGBToGrayConversion()