public void DrawLevelGraph()
 {
     try
     {
         if (ImagePath != null && ImagePath != "")
         {
             using (Bitmap bmp = new Bitmap(ImagePath))
             {
                 ImageStatisticsHSL hslStatistics = new ImageStatisticsHSL(bmp);
                 L = ConvertToPointCollection(hslStatistics.Luminance.Values);
                 ImageStatistics statistics = new ImageStatistics(bmp);
                 R = ConvertToPointCollection(statistics.Red.Values);
                 G = ConvertToPointCollection(statistics.Green.Values);
                 B = ConvertToPointCollection(statistics.Blue.Values);
             }
         }
         else
         {
             L = null;
             R = null;
             G = null;
             B = null;
         }
     }
     catch (Exception) { }
 }
Exemplo n.º 2
0
        private void GetAdditionalData(object o)
        {
            BitmapFile file = o as BitmapFile;

            try
            {
                if (!file.FileItem.IsRaw)
                {
                    using (Bitmap bmp = new Bitmap(file.FileItem.FileName))
                    {
                        // Luminance
                        ImageStatisticsHSL hslStatistics = new ImageStatisticsHSL(bmp);
                        file.LuminanceHistogramPoints = ConvertToPointCollection(hslStatistics.Luminance.Values);
                        // RGB
                        ImageStatistics rgbStatistics = new ImageStatistics(bmp);
                        file.RedColorHistogramPoints   = ConvertToPointCollection(rgbStatistics.Red.Values);
                        file.GreenColorHistogramPoints = ConvertToPointCollection(rgbStatistics.Green.Values);
                        file.BlueColorHistogramPoints  = ConvertToPointCollection(rgbStatistics.Blue.Values);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
Exemplo n.º 3
0
        private void GenerateImageHistograms(System.Drawing.Bitmap bitmap)
        {
            if (bitmap == null)
            {
                return;
            }

            try
            {
                // Luminance
                ImageStatisticsHSL hslStatistics = new ImageStatisticsHSL(bitmap);
                polygonLuminanceHistogramPoints.Points = ConvertToPointCollection(hslStatistics.Luminance.Values);
                // RGB
                ImageStatistics rgbStatistics = new ImageStatistics(bitmap);
                polygonRedColorHistogramPoints.Points   = ConvertToPointCollection(rgbStatistics.Red.Values);
                polygonGreenColorHistogramPoints.Points = ConvertToPointCollection(rgbStatistics.Green.Values);
                polygonBlueColorHistogramPoints.Points  = ConvertToPointCollection(rgbStatistics.Blue.Values);

                //bmp.Dispose();
            }
            catch
            {
                // ignored
            }
        }
Exemplo n.º 4
0
        private void RedrawCharts()
        {
            var hslStatistics   = new ImageStatisticsHSL(image);
            var luminanceValues = hslStatistics.Luminance.Values;
            var rgbStatistics   = new ImageStatistics(image);
            var redValues       = rgbStatistics.Red.Values;
            var greenValues     = rgbStatistics.Green.Values;
            var blueValues      = rgbStatistics.Blue.Values;

            luminanceChart.Series["Series1"].Points.Clear();
            redChart.Series["Series1"].Points.Clear();
            greenChart.Series["Series1"].Points.Clear();
            blueChart.Series["Series1"].Points.Clear();
            for (var i = 1; i < luminanceValues.Length; ++i)
            {
                luminanceChart.Series["Series1"].Points.AddY(luminanceValues[i]);
            }
            for (var i = 1; i < redValues.Length; ++i)
            {
                redChart.Series["Series1"].Points.AddY(redValues[i]);
            }
            for (var i = 1; i < greenValues.Length; ++i)
            {
                greenChart.Series["Series1"].Points.AddY(greenValues[i]);
            }
            for (var i = 1; i < blueValues.Length; ++i)
            {
                blueChart.Series["Series1"].Points.AddY(blueValues[i]);
            }
        }
Exemplo n.º 5
0
        public PointCollection calculateHistogram(Bitmap image)
        {
            ImageStatisticsHSL hslStatistics = new ImageStatisticsHSL(image);

            this.LuminanceHistogramPoints = canvasTool.ConvertToPointCollection(hslStatistics.Luminance.Values);

            return(LuminanceHistogramPoints);
        }
Exemplo n.º 6
0
        private void button5_Click(object sender, EventArgs e)
        {
            Bitmap eq = equalizing(bmp);

            pictureBox2.Image = eq;
            ImageStatisticsHSL hslStatistics = new ImageStatisticsHSL(eq);

            histogram5.Values = hslStatistics.Luminance.Values;
        }
Exemplo n.º 7
0
        private void button6_Click(object sender, EventArgs e)
        {
            var    imag = (Bitmap)image.Clone();
            Bitmap eq   = AddContrastFilter(imag);

            pictureBox2.Image = eq;
            ImageStatisticsHSL hslStatistics = new ImageStatisticsHSL(eq);

            histogram5.Values = hslStatistics.Luminance.Values;
        }
Exemplo n.º 8
0
        private void button7_Click(object sender, EventArgs e)
        {
            var imag = (Bitmap)image.Clone();
            // Bitmap eq = AddContrastFilter(imag);

            ImageStatisticsHSL hslStatistics = new ImageStatisticsHSL(imag);

            for (int i = 0; i < hslStatistics.Luminance.Values.Length; i++)
            {
                hslStatistics.Luminance.Values[i] = hslStatistics.Luminance.Values[i] + hScrollBar1.Value;
            }

            pictureBox2.Image = imag;
            histogram5.Values = hslStatistics.Luminance.Values;
        }
Exemplo n.º 9
0
        // Get current environment brightness
        private float get_environmentBrightness(bool raw)
        {
            Bitmap             FrameData = new Bitmap(previewBox.Image);
            ImageStatisticsHSL stat      = new ImageStatisticsHSL(FrameData);

            if (raw == true)
            {
                return(stat.Luminance.Mean); // Return the environment brightness
            }
            else
            {
                int     offset     = (int)brightnessOffset.Value;                                                               // Get offset value
                decimal percentage = Math.Round((Decimal)stat.Luminance.Mean * 100, 0, MidpointRounding.AwayFromZero) + offset; // Calc environment brightness percentage

                return(bLevels.OrderBy(x => Math.Abs((long)x - percentage)).First());                                           // Return percentage closest to possible system brightness array
            }
        }
Exemplo n.º 10
0
        private void Histogram()
        {
            try
            {
                Bitmap          image           = new Bitmap(this.pictureBox.Image);
                int[]           values          = new ImageStatisticsHSL(image).Luminance.Values;
                ImageStatistics imageStatistics = new ImageStatistics(image);
                int[]           numArray1       = SmoothHistogram(imageStatistics.Red.Values);
                int[]           numArray2       = SmoothHistogram(imageStatistics.Green.Values);
                int[]           numArray3       = SmoothHistogram(imageStatistics.Blue.Values);
                chart.Series[0].Points.Clear();
                chart.Series[1].Points.Clear();
                chart.Series[2].Points.Clear();
                chart.Legends.Clear();
                for (int index1 = 0; index1 < 3; ++index1)
                {
                    switch (index1)
                    {
                    case 0:
                        for (int index2 = 0; index2 < numArray1.Length; ++index2)
                        {
                            chart.Series[index1].Points.Add((double)numArray1[index2]);
                        }
                        break;

                    case 1:
                        for (int index2 = 0; index2 < numArray2.Length; ++index2)
                        {
                            chart.Series[index1].Points.Add((double)numArray2[index2]);
                        }
                        break;

                    case 2:
                        for (int index2 = 0; index2 < numArray3.Length; ++index2)
                        {
                            chart.Series[index1].Points.Add((double)numArray3[index2]);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
Exemplo n.º 11
0
        // Constructor
        public ColorImageStatisticsDescription(Bitmap image)
        {
            // get image dimension
            int width  = image.Width;
            int height = image.Height;

            // lock it
            BitmapData imgData = image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

            // gather statistics
            statRGB   = new ImageStatistics(imgData);
            statHSL   = new ImageStatisticsHSL(imgData);
            statYCbCr = new ImageStatisticsYCbCr(imgData);

            // unlock image
            image.UnlockBits(imgData);
        }
Exemplo n.º 12
0
        public static int[] GetLuminanceHistogram(Bitmap bitmap, int pieceTopLeftX, int pieceTopLeftY)
        {
            var mask = new byte[bitmap.Height, bitmap.Width];

            for (int x = pieceTopLeftX; x < pieceTopLeftX + Math.Min(bitmap.Width, BoardPiece.Width); x++)
            {
                for (int y = pieceTopLeftY; y < pieceTopLeftY + Math.Min(bitmap.Height, BoardPiece.Height); y++)
                {
                    mask[y, x] = 1;
                }
            }

            var st = new ImageStatisticsHSL(bitmap, mask);

            int[] luminanceValues = st.LuminanceWithoutBlack.Values;

            return(luminanceValues);
        }
Exemplo n.º 13
0
        private void UpdateHistograms(System.Drawing.Bitmap pic)
        {
            ImageStatisticsHSL hslStatistics = null;
            ImageStatistics    rgbStatistics = null;

            if (pic == null)
            {
                hslStatistics = new ImageStatisticsHSL(mainPhoto);
                rgbStatistics = new ImageStatistics(mainPhoto);
            }
            else
            {
                hslStatistics = new ImageStatisticsHSL(pic);
                rgbStatistics = new ImageStatistics(pic);
            }

            this.LuminanceHistogramPoints  = ConvertToPointCollection(hslStatistics.Luminance.Values);
            this.RedColorHistogramPoints   = ConvertToPointCollection(rgbStatistics.Red.Values);
            this.GreenColorHistogramPoints = ConvertToPointCollection(rgbStatistics.Green.Values);
            this.BlueColorHistogramPoints  = ConvertToPointCollection(rgbStatistics.Blue.Values);
        }
Exemplo n.º 14
0
        private static HistogramHash GetRGBHistogram(string file)
        {
            var values        = new List <int>();
            var histogramfile = Path.Combine(HitogramPath, Guid.NewGuid() + ".jpg");

            File.Copy(file, histogramfile);
            using (var bmp = new System.Drawing.Bitmap(histogramfile))
            {
                // Luminance
                var hslStatistics = new ImageStatisticsHSL(bmp);
                values.AddRange(hslStatistics.Luminance.Values.ToList());

                // RGB
                var rgbStatistics = new ImageStatistics(bmp);
                values.AddRange(rgbStatistics.Red.Values.ToList());
                values.AddRange(rgbStatistics.Green.Values.ToList());
                values.AddRange(rgbStatistics.Blue.Values.ToList());
            }

            File.Delete(histogramfile);

            return(new HistogramHash(file, values));
        }
Exemplo n.º 15
0
 public static Bitmap autoBrightness(Bitmap rgb, Rectangle baseRect, double baseLum)
 {
     ImageStatisticsHSL ist = null;
     if (baseRect.IsEmpty)
         ist = new ImageStatisticsHSL(rgb);
     else
         // baseRect = new Rectangle(new Point(0, 0), rgb.Size);
         ist = new ImageStatisticsHSL(new Crop(baseRect).Apply(rgb));
     //Console.WriteLine("Lum:" + ist.Luminance.Mean + " Sat:" + ist.Saturation.Mean);
     return new BrightnessCorrection(baseLum - ist.Luminance.Mean).Apply(rgb);
 }
Exemplo n.º 16
0
        private void button1_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog();

            if (ofd.ShowDialog(this) == DialogResult.OK)
            {
                image = System.Drawing.Image.FromFile(ofd.FileName);
                //pictureBox2.Height = System.Drawing.Image.FromFile(ofd.FileName).Height;
                // pictureBox2.Width = System.Drawing.Image.FromFile(ofd.FileName).Width;
                //image.set = System.Drawing.Image.FromFile(ofd.FileName).Height;
            }


            pictureBox1.Image = image;
            //pictureBoxBoxStart.SizeMode = PictureBoxSizeMode.StretchImage;
            //pictureBoxBoxEnd.SizeMode = PictureBoxSizeMode.StretchImage;
            // pictureBox1.Image = CalculateBarChart(image);


            bmp = new System.Drawing.Bitmap(ofd.FileName);
            // Luminance
            ImageStatisticsHSL hslStatistics = new ImageStatisticsHSL(bmp);

            int[] luminanceValues = hslStatistics.Luminance.Values;
            // RGB
            ImageStatistics rgbStatistics = new ImageStatistics(bmp);

            int[] redValues   = rgbStatistics.Red.Values;
            int[] greenValues = rgbStatistics.Green.Values;
            int[] blueValues  = rgbStatistics.Blue.Values;

            /* List<Vector2> l = ConvertToPointCollection(hslStatistics.Luminance.Values);
             * //List<Vector2> r = ConvertToPointCollection(rgbStatistics.Red.Values);
             * Point[] points = new Point[l.Count];
             *
             * for (int i = 0; i < l.Count; i++)
             * {
             *   float x = l.ElementAt(i).X;
             *   float y = l.ElementAt(i).Y;
             *
             *   //points[i] = new Point((int)x, (int)y);
             *   Console.WriteLine("x " + x + " y " + y);
             *   chart1.Series[0].Points.AddXY(x, y);
             *
             * }*/
            AForge.Math.Histogram activeHistogram = null;
            ImageStatistics       stat;

            // var imag = (Bitmap)image.Clone();
            stat              = new ImageStatistics(bmp);
            histogram1.Color  = Color.Red;
            histogram2.Color  = Color.Green;
            histogram3.Color  = Color.Blue;
            histogram4.Color  = Color.Black;
            activeHistogram   = stat.Red;
            histogram1.Values = activeHistogram.Values;
            activeHistogram   = stat.Green;
            histogram2.Values = activeHistogram.Values;
            activeHistogram   = stat.Blue;
            histogram3.Values = activeHistogram.Values;

            //activeHistogram = hslStatistics.;
            histogram4.Values = hslStatistics.Luminance.Values;

            /*Graphics g = CreateGraphics();
             * g.DrawPolygon(Pens.Gray, points);*/
        }
Exemplo n.º 17
0
        public static double Luminance(this Bitmap bitmap)
        {
            var s = new ImageStatisticsHSL(bitmap);

            return(s.Luminance.Mean);
        }
Exemplo n.º 18
0
        public static double Saturation(this Bitmap bitmap)
        {
            var s = new ImageStatisticsHSL(bitmap);

            return(s.Saturation.Mean);
        }
Exemplo n.º 19
0
        public ImageStat GetImageStats(string fullPath, FormOptions options)
        {
            if (cancelAnalysis)
            {
                return(null);
            }

            Messaging.Talk($"{fullPath}");

            ImageStat res = null;

            try
            {
                res = new ImageStat();


                res.ImagePath = fullPath.Replace(options.ImagesSoureDirectory, string.Empty);
                res.Length    = _fileSystemService.GetFileLength(fullPath);

                // load file
                using (var image = _imageService.GetThumb(fullPath, _configService.TempBitmapHeight))
                {
                    // hsl
                    //Talk($"{fullPath} HSL... ");
                    var statsHSL = new ImageStatisticsHSL(image);
                    res.Luminance = (decimal)statsHSL.Luminance.Median;
                    res.Pixels    = statsHSL.PixelsCount;

                    // rgb
                    //Talk($"{fullPath} RGB... ");
                    var stats = new ImageStatistics(image);
                    res.Blue   = stats.Blue.Median;
                    res.Red    = stats.Red.Median;
                    res.Green  = stats.Green.Median;
                    res.Pixels = stats.PixelsCount;

                    res.BlueMax  = stats.Blue.Max;
                    res.RedMax   = stats.Red.Max;
                    res.GreenMax = stats.Green.Max;

                    res.BlueMin  = stats.Blue.Min;
                    res.RedMin   = stats.Red.Min;
                    res.GreenMin = stats.Green.Min;

                    // YCbCr
                    // Talk($"{fullPath} YCbCr... ");
                    var statsYCbCr = new ImageStatisticsYCbCr(image);
                    res.Cb = statsYCbCr.Cb.Mean;
                    res.Cr = statsYCbCr.Cr.Mean;
                    res.Y  = statsYCbCr.Y.Mean;
                }
            }
            catch (Exception e)
            {
                res = null;
                Messaging.Talk($"{fullPath} Error! {e.Message}... ");
                Messaging.RaiseProgress(null, new ProgressBarEventArgs {
                    EventKindOf = EventKind.IncrementError
                });
            }
            finally
            {
                Messaging.RaiseProgress(null, new ProgressBarEventArgs {
                    EventKindOf = EventKind.Increment
                });
            }

            return(res);
        }