Пример #1
0
        public static double[][] TransformationMatrix(ColorSpace colorSpace, doublePoint whitePoint)
        {
            double[][] value = new double[3][];
            value[0] = new double[3] {
                colorSpace.Red.X, colorSpace.Green.X, colorSpace.Blue.X
            };
            value[1] = new double[3] {
                colorSpace.Red.Y, colorSpace.Green.Y, colorSpace.Blue.Y
            };
            value[2] = new double[3];
            for (int i = 0; i < 3; i++)
            {
                value[2][i] = 1 - value[1][i] - value[0][i];
            }

            double[][] WPvector = new double[3][];
            WPvector[0] = new double[1] {
                whitePoint.X / whitePoint.Y
            };
            WPvector[1] = new double[1] {
                1
            };
            WPvector[2] = new double[1] {
                (1 - whitePoint.X - whitePoint.Y) / whitePoint.Y
            };

            double[][] result = MatrixCalculations.MatrixProduct((MatrixCalculations.MatrixInverse(value)), WPvector);
            double[][] temp   = MatrixCalculations.MatrixCreate(3, 3);
            for (int i = 0; i < 3; i++)
            {
                temp[i][i] = result[i][0];
            }
            result = MatrixCalculations.MatrixProduct(value, temp);
            return(result);
        }
 public ColorSpace(doublePoint red, doublePoint green, doublePoint blue, double gamma, string illuminnant)
 {
     Red              = red;
     Green            = green;
     Blue             = blue;
     this.Gamma       = gamma;
     this.illuminnant = illuminnant;
 }
Пример #3
0
        public static bool ToLAB(ref GlobalObjects GObjects, ColorSpace colorSpace, doublePoint whitePoint)
        {
            if (GObjects.MainPicture == null)
            {
                return(false);
            }
            GObjects.Chanel1 = new DirectBitmap(GObjects.MainPicture.Width, GObjects.MainPicture.Height);
            GObjects.Chanel2 = new DirectBitmap(GObjects.MainPicture.Width, GObjects.MainPicture.Height);
            GObjects.Chanel3 = new DirectBitmap(GObjects.MainPicture.Width, GObjects.MainPicture.Height);

            double[][] matrix   = TransformationMatrix(colorSpace, whitePoint);
            double[][] WPvector = new double[][] { new double[] { whitePoint.X / whitePoint.Y }, new double[] { 1 }, new double[] { (1 - whitePoint.X - whitePoint.Y) / whitePoint.Y } };
            for (int i = 0; i < GObjects.MainPicture.Height; i++)
            {
                for (int j = 0; j < GObjects.MainPicture.Width; j++)
                {
                    double R = Math.Pow(GObjects.MainPicture.GetPixel(j, i).R / 255.0, colorSpace.Gamma);
                    double G = Math.Pow(GObjects.MainPicture.GetPixel(j, i).G / 255.0, colorSpace.Gamma);
                    double B = Math.Pow(GObjects.MainPicture.GetPixel(j, i).B / 255.0, colorSpace.Gamma);

                    double[][] RGBvector = new double[][] { new double[] { R }, new double[] { G }, new double[] { B } };
                    double[][] XYZvector = MatrixCalculations.MatrixProduct(matrix, RGBvector);

                    var Values = VectorFunction(XYZvector[0][0] / WPvector[0][0], XYZvector[1][0] / WPvector[1][0], XYZvector[2][0] / WPvector[2][0]);

                    int Lvalue = Convert.ToInt32(116 * Values.fy - 16);
                    int Avalue = Convert.ToInt32(500 * (Values.fx - Values.fy));
                    int Bvalue = Convert.ToInt32(200 * (Values.fy - Values.fz));

                    GObjects.Chanel1.SetPixel(j, i, Color.FromArgb(Math.Max(Math.Min(255, Lvalue), 0), Math.Max(Math.Min(255, Lvalue), 0), Math.Max(Math.Min(255, Lvalue), 0)));
                    GObjects.Chanel2.SetPixel(j, i, Color.FromArgb(Math.Max(0, Math.Min(255, 127 + Avalue)), Math.Max(0, Math.Min(255, 127 - Avalue)), 127));
                    GObjects.Chanel3.SetPixel(j, i, Color.FromArgb(Math.Max(0, Math.Min(255, 127 + Bvalue)), 127, Math.Max(0, Math.Min(255, 127 - Bvalue))));
                }
            }
            return(true);
        }