Пример #1
0
        ///Constructor

        /// <summary>
        ///
        /// </summary>
        /// <param name="col">Drawing Color from the pixel</param>
        public PicturePixelInfos(Color col)
        {
            Pix     = col;
            Counter = 1;
            Hsv     = new double[3];
            Lab     = new double[3];

            Hsv             = ColorSpace.RGB2HSV(Pix);
            Lab             = ColorSpace.RGB2Lab(Pix);
            DistanceToWhite = ColorSpace.ColorDistance2(this.Lab, ColorSpace.RGB2Lab(Color.White));
        }
Пример #2
0
        //Das hier alles testen und weitermachen 26.10.2017
        /// <summary>
        /// Calculate the distance to palette 0..4
        /// </summary>
        /// <param name="item">color of the original palette element of sortedList</param>
        /// <param name="palBitmap">Bitmap from Palette 0..4</param>
        public static void CalcDistances(int calcMode, ref OriginalColor item, params Bitmap[] palBitmap)
        {
            // distance to palette 0..4
            double[] distance = new double[palBitmap.Length];

            // Minium distance to palette 0..4
            double[] minDistance = new double[palBitmap.Length];
            // Initialize Minimum with max. from Double
            for (int i = 0; i < minDistance.Length; i++)
            {
                minDistance[i] = Double.MaxValue;
            }

            //Lab-color from item
            double[] lab0 = new double[3];
            lab0 = ColorSpace.RGB2Lab(item.Pix);

            //Lab-color from palette
            double[] lab1 = new double[3];

            //HSV-color from item
            double[] hsv0 = new double[3];
            hsv0 = ColorSpace.RGB2HSV(item.Pix);

            //Lab-color from palette
            double[] hsv1 = new double[3];

            // j = Palette Bitmap 0 ..4
            for (int j = 0; j < palBitmap.Length; j++)
            {
                //Calculate the min distance to palette 0..4
                if (palBitmap[j] != null)
                {
                    for (int x = 0; x < palBitmap[j].Width; x++)
                    {
                        for (int y = 0; y < palBitmap[j].Height; y++)
                        {
                            lab1 = ColorSpace.RGB2Lab(palBitmap[j].GetPixel(x, y));
                            hsv1 = ColorSpace.RGB2HSV(palBitmap[j].GetPixel(x, y));
                            if (calcMode == 0) // Color-distance
                            {
                                distance[j] = ColorSpace.ColorDistance2(lab0, lab1);
                            }
                            if (calcMode == 1) // HSV-Color H (Farbwert)
                            {
                                distance[j] = Math.Abs(hsv0[0] - hsv1[0]);
                            }
                            if (calcMode == 2) // HSV-Color S (Sätigung)
                            {
                                distance[j] = Math.Abs(hsv0[1] - hsv1[1]);
                            }
                            if (calcMode == 3) // HSV-Color V (Hellwert)
                            {
                                distance[j] = Math.Abs(hsv0[2] - hsv1[2]);
                            }
                            if (distance[j] < minDistance[j])
                            {
                                minDistance[j] = distance[j];
                            }
                        }
                    }

                    switch (j)
                    {
                    case 0:
                    {
                        item.DistanceTo0 = minDistance[j];         // Min Distance to palette 0
                        break;
                    }

                    case 1:
                    {
                        item.DistanceTo1 = minDistance[j];         // Min Distance to palette 1
                        break;
                    }

                    case 2:
                    {
                        item.DistanceTo2 = minDistance[j];         // Min Distance to palette 2
                        break;
                    }

                    case 3:
                    {
                        item.DistanceTo3 = minDistance[j];         // Min Distance to palette 3
                        break;
                    }

                    case 4:
                    {
                        item.DistanceTo4 = minDistance[j];         // Min Distance to palette 4
                        break;
                    }

                    default:
                        // Error no more palettes
                        break;
                    }
                }
            }
        }
Пример #3
0
        public OriginalColor(int calcMode, Color pix, Bitmap[] bitmapPalette)
        {
            this.calcMode      = calcMode;
            Pix                = pix;
            this.bitmapPalette = bitmapPalette;

            int jMin = -1;

            // distance to palette 0..4
            double[] distance = new double[4];

            // Minium distance to palette 0..4
            double[] minDistance = new double[4];

            //Lab-color from item
            double[] lab0 = new double[3];
            lab0 = ColorSpace.RGB2Lab(pix);

            //Lab-color from palette
            double[] lab1 = new double[3];

            //HSV-color from item
            double[] hsv0 = new double[3];
            hsv0 = ColorSpace.RGB2HSV(pix);

            //Lab-color from palette
            double[] hsv1 = new double[3];

            // j = Palette Bitmap 0 ..4
            for (int j = 0; j < bitmapPalette.Length; j++)
            {
                //Calculate the min distance to palette 0..4
                this.distanceMinIndex = -1;
                this.DistanceMin      = Double.MaxValue;
                this.DistanceTo0      = Double.MaxValue;
                this.DistanceTo1      = Double.MaxValue;
                this.DistanceTo2      = Double.MaxValue;
                this.DistanceTo3      = Double.MaxValue;
                this.DistanceTo4      = Double.MaxValue;

                if (bitmapPalette[j] != null)
                {
                    minDistance[j] = Double.MaxValue;

                    for (int x = 0; x < bitmapPalette[j].Width; x++)
                    {
                        for (int y = 0; y < bitmapPalette[j].Height; y++)
                        {
                            lab1 = ColorSpace.RGB2Lab(bitmapPalette[j].GetPixel(x, y));
                            hsv1 = ColorSpace.RGB2HSV(bitmapPalette[j].GetPixel(x, y));
                            if (calcMode == 0) // Color-distance
                            {
                                distance[j] = ColorSpace.ColorDistance2(lab0, lab1);
                            }
                            if (calcMode == 1) // HSV-Color H (Farbwert)
                            {
                                distance[j] = Math.Abs(hsv0[0] - hsv1[0]);
                            }
                            if (calcMode == 2) // HSV-Color S (Sätigung)
                            {
                                distance[j] = Math.Abs(hsv0[1] - hsv1[1]);
                            }
                            if (calcMode == 3) // HSV-Color V (Hellwert)
                            {
                                distance[j] = Math.Abs(hsv0[2] - hsv1[2]);
                            }
                            if (distance[j] < minDistance[j])
                            {
                                minDistance[j] = distance[j];
                                jMin           = j;
                                if (j == 0)
                                {
                                    this.DistanceTo0 = minDistance[j];
                                }
                                if (j == 1)
                                {
                                    this.DistanceTo1 = minDistance[j];
                                }
                                if (j == 2)
                                {
                                    this.DistanceTo2 = minDistance[j];
                                }
                                if (j == 3)
                                {
                                    this.DistanceTo3 = minDistance[j];
                                }
                                if (j == 4)
                                {
                                    this.DistanceTo4 = minDistance[j];
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
        public ImitationColor(int calcMode, double[] correction, Color pix, Bitmap[] palBitmap)
        {
            //default settings
            PaletteNewColor   = Color.FromArgb(0, 222, 222, 222);
            TargetIndex       = -1;
            PaletteListIndex  = -1;
            OriginalIndex     = -1;
            OriginalListIndex = -1;

            int jMin = -1;

            Pix = pix;

            // distance to palette 0..4
            double distance = Double.MaxValue;

            // Minium distance to palette 0..4
            double minDistance = Double.MaxValue;

            //Lab-color from item
            double[] lab0 = new double[3];
            lab0 = ColorSpace.RGB2Lab(pix);

            //Lab-color from palette
            double[] lab1 = new double[3];

            //HSV-color from item
            double[] hsv0 = new double[3];
            hsv0 = ColorSpace.RGB2HSV(pix);

            //Lab-color from palette
            double[] hsv1 = new double[3];

            // j = Palette Bitmap 0 ..4
            for (int j = 0; j < palBitmap.Length; j++)
            {
                //Calculate the min distance to palette 0..4
                if (palBitmap[j] != null)
                {
                    for (int x = 0; x < palBitmap[j].Width; x++)
                    {
                        for (int y = 0; y < palBitmap[j].Height; y++)
                        {
                            lab1 = ColorSpace.RGB2Lab(palBitmap[j].GetPixel(x, y));
                            hsv1 = ColorSpace.RGB2HSV(palBitmap[j].GetPixel(x, y));
                            if (calcMode == 0) // Color-distance
                            {
                                distance = ColorSpace.ColorDistance2(lab0, lab1) - correction[j];
                            }
                            if (calcMode == 1) // HSV-Color H (Farbwert)
                            {
                                distance = Math.Abs(hsv0[0] - hsv1[0]) - correction[j];
                            }
                            if (calcMode == 2) // HSV-Color S (Sätigung)
                            {
                                distance = Math.Abs(hsv0[1] - hsv1[1]) - correction[j];
                            }
                            if (calcMode == 3) // HSV-Color V (Hellwert)
                            {
                                distance = Math.Abs(hsv0[2] - hsv1[2]) - correction[j];
                            }
                            if (distance < minDistance)
                            {
                                minDistance = distance;
                                jMin        = j;
                            }
                        }
                    }
                }
            }
            this.PaletteIndex = jMin;
        }