예제 #1
0
        // Increase all pixel's hue with the given degree value
        public static Mat IncreaseHueBy(Mat original, double degree)
        {
            Image <Bgr, byte> image = original.ToImage <Bgr, byte>();
            int rows = image.Rows;
            int cols = image.Cols;
            Bgr color;

            for (int row = 0; row < rows; ++row)
            {
                for (int col = 0; col < cols; ++col)
                {
                    color           = image[row, col];
                    color           = HSL.IncreaseHue(color, degree);
                    image[row, col] = color;
                }
            }

            return(image.Mat);
        }
예제 #2
0
        // Increase all pixel's lightness with the given percentage value
        public static Mat IncreaseLightnessBy(Mat original, double percentage)
        {
            Image <Bgr, byte> image = original.ToImage <Bgr, byte>();
            int rows = image.Rows;
            int cols = image.Cols;
            Bgr color;

            for (int row = 0; row < rows; ++row)
            {
                for (int col = 0; col < cols; ++col)
                {
                    color           = image[row, col];
                    color           = HSL.IncreaseLightness(color, percentage / 100.0);
                    image[row, col] = color;
                }
            }

            return(image.Mat);
        }
예제 #3
0
        // Convert HSL color to Bgr color
        public static Bgr ConvertToBgr(HSL hslColor)
        {
            int blue  = (int)(hslColor.L * 255);
            int green = (int)(hslColor.L * 255);
            int red   = (int)(hslColor.L * 255);

            double h = hslColor.H;
            double s = hslColor.S;
            double l = hslColor.L;

            if (hslColor.S != 0)
            {
                double hue = h / 360;
                double v1  = (l < 0.5) ? (l * (1 + s)) : ((l + s) - (l * s));
                double v2  = 2 * l - v1;

                red   = (int)(255 * HueToRgb(v2, v1, hue + (1 / 3.0)));
                green = (int)(255 * HueToRgb(v2, v1, hue));
                blue  = (int)(255 * HueToRgb(v2, v1, hue - (1 / 3.0)));
            }

            return(new Bgr(blue, green, red));
        }
예제 #4
0
        // Stretch images histogram based on the lightness values
        public static Image <Bgr, byte> StrectchHistogram(Mat original)
        {
            Image <Bgr, byte> image = original.ToImage <Bgr, byte>();
            double            minL;
            double            maxL;
            Bgr color;

            int rows = image.Rows;
            int cols = image.Cols;

            GetMinAndMaxLightness(image, out minL, out maxL);

            for (int row = 0; row < rows; ++row)
            {
                for (int col = 0; col < cols; ++col)
                {
                    color           = image[row, col];
                    image[row, col] = HSL.StretchValue(color, maxL - minL);
                }
            }

            return(image);
        }
예제 #5
0
        // Returns the smallest and biggest lightness values from the given image
        private static void GetMinAndMaxLightness(Image <Bgr, byte> image, out double min, out double max)
        {
            double minTemp = double.MaxValue;
            double maxTemp = double.MinValue;
            double lightness;

            int rows = image.Rows;
            int cols = image.Cols;

            for (int row = 0; row < rows; ++row)
            {
                for (int col = 0; col < cols; ++col)
                {
                    Bgr color = image[row, col];
                    lightness = HSL.GetLightness(color);
                    minTemp   = Math.Min(minTemp, lightness);
                    maxTemp   = Math.Max(maxTemp, lightness);
                }
            }

            min = minTemp;
            max = maxTemp;
        }