Ejemplo n.º 1
0
        internal static IRgb ToColor(ILch item)
        {
            var hRadians = item.H * Math.PI / 180.0;
            var lab      = new Lab
            {
                L = item.L,
                A = Math.Cos(hRadians) * item.C,
                B = Math.Sin(hRadians) * item.C
            };

            return(lab.To <Rgb>());
        }
Ejemplo n.º 2
0
        private bool Max_range(Lab labPixel, Lab labBefore, int treshold, ref Lab labRange)
        {
            if (Math.Abs(labPixel.L - labBefore.L) < treshold)
            {
                labRange.L = labPixel.L - labBefore.L;
            }

            if (Math.Abs(labPixel.A - labBefore.A) < treshold)
            {
                labRange.A = labPixel.A - labBefore.A;
            }
            if (Math.Abs(labPixel.B - labBefore.B) < treshold)
            {
                labRange.B = labPixel.B - labBefore.B;
            }

            var evklidRange = Math.Sqrt((labPixel.L - labBefore.L) * (labPixel.L - labBefore.L) +
                                        (labPixel.A - labBefore.A) * (labPixel.A - labBefore.A) +
                                        (labPixel.B - labBefore.B) * (labPixel.B - labBefore.B));

            return(evklidRange < treshold);
        }
Ejemplo n.º 3
0
        private Image ApplyFilterLab(Image image)
        {
            _colBefore = pnlSourceColor.BackColor;
            _colAfter  = pnlResultColor.BackColor;
            _treshold  = trcThreshHold.Value;
            _labBefore = new Rgb {
                R = _colBefore.R, G = _colBefore.G, B = _colBefore.B
            }.To <Lab>();
            _labAfter = new Rgb {
                R = _colAfter.R, G = _colAfter.G, B = _colAfter.B
            }.To <Lab>();


            var img = new Bitmap(image);

            for (var i = 0; i < img.Width; i++)
            {
                for (var j = 0; j < img.Height; j++)
                {
                    _pixel    = img.GetPixel(i, j);
                    _labPixel = (_rgbPixel = new Rgb {
                        R = _pixel.R, G = _pixel.G, B = _pixel.B
                    }).To <Lab>();

                    if (Max_range(_labPixel, _labBefore, _treshold, ref _labRange))
                    {
                        _labPixel.L = _labAfter.L + _labRange.L;
                        _labPixel.A = _labAfter.A + _labRange.A;
                        _labPixel.B = _labAfter.B + _labRange.B;
                        _rgbPixel   = _labPixel.To <Rgb>();

                        if (_rgbPixel.R < 0)
                        {
                            _rgbPixel.R = 0;
                        }
                        if (_rgbPixel.R > 255)
                        {
                            _rgbPixel.R = 255;
                        }
                        if (_rgbPixel.G < 0)
                        {
                            _rgbPixel.G = 0;
                        }
                        if (_rgbPixel.G > 255)
                        {
                            _rgbPixel.G = 255;
                        }
                        if (_rgbPixel.B < 0)
                        {
                            _rgbPixel.B = 0;
                        }
                        if (_rgbPixel.B > 255)
                        {
                            _rgbPixel.B = 255;
                        }

                        img.SetPixel(i, j, Color.FromArgb((int)_rgbPixel.R, (int)_rgbPixel.G, (int)_rgbPixel.B));
                    }
                }
            }
            return(img);
        }