示例#1
0
        public override Image ToGray(GrayscaleConversionMethod method = GrayscaleConversionMethod.ARITHMETIC_MEAN)
        {
            ImageGray <T> grayImage = (ImageGray <T>)ImageFactory.Create(Width, Height, ColorModel.GRAY, GetDataType());
            Func <double, double, double, double> conversionFunction;

            switch (method)
            {
            case GrayscaleConversionMethod.GEOMETRIC_MEAN:
                conversionFunction = (r, g, b) => Math.Pow(r * g * b, 1.0 / 3.0);
                break;

            case GrayscaleConversionMethod.HARMONIC_MEAN:
                conversionFunction = (r, g, b) => 3.0 / (1.0 / r + 1.0 / g + 1.0 / b);
                break;

            default:
                conversionFunction = (r, g, b) => (r + g + b) / 3.0;
                break;
            }
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    grayImage.SetPixelValueFromDouble(x, y, conversionFunction(Convert.ToDouble(R.Pixels[x, y]), Convert.ToDouble(G.Pixels[x, y]), Convert.ToDouble(B.Pixels[x, y])));
                }
            }
            return(grayImage);
        }
示例#2
0
 public override Image ToGray(GrayscaleConversionMethod method = GrayscaleConversionMethod.ARITHMETIC_MEAN)
 {
     return(Clone());
 }
示例#3
0
 public override Image ToGray(GrayscaleConversionMethod method = GrayscaleConversionMethod.ARITHMETIC_MEAN)
 {
     return(ToRGB().ToGray(method));
 }
示例#4
0
 public abstract Image ToGray(GrayscaleConversionMethod method = GrayscaleConversionMethod.ARITHMETIC_MEAN);