Exemplo n.º 1
0
        private byte[] GetAdditiveMultiplicatedPixel(byte[] values, int byteLength, double[] matrix)
        {
            var RGBColors = PixelOperations.TransformPixelArrayToColorArray(values, byteLength);

            double red   = 0;
            double green = 0;
            double blue  = 0;
            double sum   = 0;

            for (int i = 0; i < 9; i++)
            {
                red   += RGBColors[i].R * matrix[i];
                green += RGBColors[i].G * matrix[i];
                blue  += RGBColors[i].B * matrix[i];
                sum   += matrix[i];
            }

            if (sum <= 0)
            {
                sum = 1;
            }

            red /= sum;
            if (red < 0)
            {
                red = 0;
            }
            if (red > 255)
            {
                red = 255;
            }

            green /= sum;
            if (green < 0)
            {
                green = 0;
            }
            if (green > 255)
            {
                green = 255;
            }

            blue /= sum;
            if (blue < 0)
            {
                blue = 0;
            }
            if (blue > 255)
            {
                blue = 255;
            }

            Color color = Color.FromArgb(RGBColors[4].A, (int)red, (int)green, (int)blue);

            byte[] pixel = PixelOperations.TransformColorToPixel(color, byteLength);
            return(pixel);
        }
Exemplo n.º 2
0
        private byte[] GetMedian(byte[] values, int byteLength, int pixelCount)
        {
            List <Color> RGBColors = PixelOperations.TransformPixelArrayToColorArray(values, byteLength).ToList();

            RGBColors.Sort((x, y) => x.GetBrightness().CompareTo(y.GetBrightness()));
            Color color = RGBColors[pixelCount * pixelCount / 2];

            byte[] pixel = PixelOperations.TransformColorToPixel(color, byteLength);
            return(pixel);
        }
Exemplo n.º 3
0
        private byte[] GetMonohromePixel(byte[] pixel, int byteLength, int coefficient)
        {
            Color color = PixelOperations.TransformPixelToColor(pixel, byteLength);
            Color newColor;

            if ((color.B + color.G + color.R) / 3 < coefficient)
            {
                newColor = SetNewColor(color, secondColor);
            }
            else
            {
                newColor = SetNewColor(color, firstColor);
            }
            pixel = PixelOperations.TransformColorToPixel(newColor, byteLength);
            return(pixel);
        }