示例#1
0
        public static void DrawHistogram(Bitmap graph)
        {
            switch (mode)
            {
            case ImageHistogramHsvMode.Standart:
                ImageHistogramHsvExist.DrawHistogram(graph);
                break;

            case ImageHistogramHsvMode.Distribution:
                ImageHistogramHsvOcc.DrawHistogram(graph);
                break;

            case ImageHistogramHsvMode.Vals:
                ImageHistogramHsvOcc.DrawHistogram(graph);
                break;

            case ImageHistogramHsvMode.Power:
                ImageHistogramHsvOcc.DrawHistogram(graph);
                break;

            case ImageHistogramHsvMode.None:
                break;
            }
        }
示例#2
0
        public static void ComputeHistogram(Bitmap input, string param)
        {
            param = param.Trim();

            bool ColorPalete = (param[0] == ColorPaleteCommnad); //ColorPalete
            bool Histogram   = (param[0] == HistogramCommnad);   //Histogram
            bool Values      = (param[0] == ValuesCommnad);      //Values
            bool Powers      = (param[0] == PowersCommnad);      //Powers

            bool total = ColorPalete || Histogram || Values || Powers;

            bool onlyOne = BoolMath.OnlyOne(ColorPalete, Histogram, Values, Powers);

            if (!total)
            {
                MessageBox.Show("Missing starting command");
                mode = ImageHistogramHsvMode.None;
                return;
            }
            if (!onlyOne)
            {
                MessageBox.Show("To many commands");
                mode = ImageHistogramHsvMode.None;
                return;
            }

            if (ColorPalete)
            {
                mode  = ImageHistogramHsvMode.Standart;
                param = param.Substring(param.IndexOf(ColorPaleteCommnad) + 1);
                Dictionary <string, string> rec = Util.ParseKeyValueList(param, ' ');


                int hue        = ImageHistogramHsvExist.OptimalHue;
                int saturation = ImageHistogramHsvExist.OptimalSaturation;

                Util.TryParse(rec, "Hue", ref hue);
                RangeMath.InRangeOrDefault(ref hue, ImageHistogramHsvExist.MinHue, ImageHistogramHsvExist.MaxHue, ImageHistogramHsvExist.OptimalHue);
                Util.TryParse(rec, "Sat", ref saturation);
                RangeMath.InRangeOrDefault(ref saturation, ImageHistogramHsvExist.MinSaturation, ImageHistogramHsvExist.MaxSaturation, ImageHistogramHsvExist.OptimalSaturation);

                if (rec.ContainsKey("Colors") && rec["Colors"] == "Dynamic")
                {
                    ImageHistogramHsvExist.DynamicColors = true;
                }
                else if (rec.ContainsKey("Colors") && rec["Colors"] == "Discrete")
                {
                    ImageHistogramHsvExist.DynamicColors = false;
                }
                else
                {
                    ImageHistogramHsvExist.DynamicColors = true;
                }
                ImageHistogramHsvExist.ComputeHistogram(input, hue, saturation + 1);
            }
            else if (Histogram || Powers || Values)
            {
                if (Histogram)
                {
                    mode  = ImageHistogramHsvMode.Distribution;
                    param = param.Substring(param.IndexOf(HistogramCommnad) + 1);
                }
                if (Values)
                {
                    mode  = ImageHistogramHsvMode.Vals;
                    param = param.Substring(param.IndexOf(ValuesCommnad) + 1);
                }
                if (Powers)
                {
                    mode  = ImageHistogramHsvMode.Power;
                    param = param.Substring(param.IndexOf(PowersCommnad) + 1);
                }

                Dictionary <string, string> rec = Util.ParseKeyValueList(param, ' ');

                int   hue  = ImageHistogramHsvOcc.OptimalHue;
                float zoom = ImageHistogramHsvOcc.OptimalZoom;
                Util.TryParse(rec, "Hue", ref hue);
                RangeMath.InRangeOrDefault(ref hue, ImageHistogramHsvOcc.MinHue, ImageHistogramHsvOcc.MaxHue, ImageHistogramHsvOcc.OptimalHue);
                if (!Util.TryParse(rec, "Zoom", ref zoom) && rec.ContainsKey("Zoom") && (rec["Zoom"] == "A" || rec["Zoom"] == "Auto"))
                {
                    ImageHistogramHsvOcc.AutoZoom = true;
                }
                else
                {
                    ImageHistogramHsvOcc.AutoZoom = false;
                }
                ImageHistogramHsvOcc.Zoom = zoom;
                ImageHistogramHsvOcc.ComputeHistogram(input, mode, hue + 1);
            }
        }