Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            dm.SaveInMask = cbUseMask.Checked;
            dm.FindPixels((int)m.Value, (double)n.Value, (double)k.Value, color.Checked);
            pictureBox2.Image = ImageTransform.BoolToBitmap(dm.PollutedMask);

            savedMask2 = Tools.ArrayTools.CopyArray <bool>(dm.PollutedMask);

            tbLog.Text += Tools.Metrics.MatrixDifference(savedMask, savedMask2, MetricsMode.Simple);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Count() == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
            else
            {
                var myImage = new MyImage();
                myImage.Bitmap = new Bitmap(args[0]);

                var dataMining = new DataMining();
                //string log = string.Format("Файл: {0}\nМетод: {1}\nШаблон: {2}\nОбрезать пиксели: {3}\nДостоверность, %: {4}\nДлина шаблона: {5}\nПроцент загрязнения: {6}\nИспользование маски: {7}\n", args);

                dataMining.CollectionMethod = int.Parse(args[1]);
                dataMining.Template         = int.Parse(args[2]);
                dataMining.CropPixels       = int.Parse(args[3]) == 1;
                dataMining.MaxAccuracy      = int.Parse(args[4]);
                dataMining.MaxDepth         = int.Parse(args[5]);
                int pollutedPercent = 0;
                if (int.TryParse(args[6], out pollutedPercent))
                {
                    dataMining.PollutePercent = pollutedPercent;
                }
                else
                {
                    dataMining.PollutePercent = -1;
                }
                dataMining.UseMask  = int.Parse(args[7]) == 1;
                dataMining.WSM      = int.Parse(args[8]) == 1;
                dataMining.UseLimit = int.Parse(args[9]) == 1;

                dataMining.MyImage = myImage;
                //dataMining.UpdateLog += (o, eo) =>
                //{
                //    log += eo.Object;
                //};

                string metricsOrig = dataMining.GetMetricsText(MetricsMode.CSVSimple);
                if (dataMining.PollutePercent != -1)
                {
                    dataMining.Pollute(int.Parse(args[10]) == 1);
                    dataMining.MyImage.Bitmap.Save(args[0] + "_polluted.png", ImageFormat.Png);
                }
                else
                {
                    var pollutedImage = new MyImage();
                    pollutedImage.Bitmap = new Bitmap(args[6]);
                    for (int i = 0; i < pollutedImage.ImageWidth; i++)
                    {
                        for (int j = 0; j < pollutedImage.ImageHeight; j++)
                        {
                            dataMining.MyImage.ImageBytes[i, j] = pollutedImage.ImageBytes[i, j];
                        }
                    }
                    dataMining.PollutedImage        = Tools.ArrayTools.CopyArray <int>(pollutedImage.ImageBytes);
                    dataMining.PollutedMask         = new bool[pollutedImage.ImageWidth, pollutedImage.ImageHeight];
                    dataMining.PollutedMaskOriginal = new bool[pollutedImage.ImageWidth, pollutedImage.ImageHeight];
                }

                string metricsPolluted = dataMining.GetMetricsText(MetricsMode.CSVSimple);
                dataMining.CreatePairs();

                if (!dataMining.UseMask)
                {
                    dataMining.FindPixels();
                }

                bool[,] maskOriginal;
                bool[,] maskStatistics;
                dataMining.GetMasks(out maskOriginal, out maskStatistics);

                bool[,] maskMiss  = new bool[maskOriginal.GetLength(0), maskOriginal.GetLength(1)];
                bool[,] maskFalse = new bool[maskOriginal.GetLength(0), maskOriginal.GetLength(1)];
                if (maskStatistics != null)
                {
                    for (int i = 0; i < maskOriginal.GetLength(0); i++)
                    {
                        for (int j = 0; j < maskOriginal.GetLength(1); j++)
                        {
                            maskMiss[i, j]  = maskOriginal[i, j] && !maskStatistics[i, j];
                            maskFalse[i, j] = !maskOriginal[i, j] && maskStatistics[i, j];
                        }
                    }
                }
                if (maskStatistics != null)
                {
                    ImageTransform.BoolToBitmap(maskStatistics).Save(args[0] + "_maskStatistics.png", ImageFormat.Png);
                }
                ImageTransform.BoolToBitmap(maskOriginal).Save(args[0] + "_maskOriginal.png", ImageFormat.Png);
                ImageTransform.BoolToBitmap(maskMiss).Save(args[0] + "_maskMiss.png", ImageFormat.Png);
                ImageTransform.BoolToBitmap(maskFalse).Save(args[0] + "_maskFalse.png", ImageFormat.Png);

                dataMining.RestoreImage();
                dataMining.MyImage.Bitmap.Save(args[0] + "_restored.png", ImageFormat.Png);
                string metricsRestored = dataMining.GetMetricsText(MetricsMode.CSVSimple);

                string log = string.Empty;

                if (!File.Exists("Statistics.csv"))
                {
                    log += string.Join(Tools.Consts.CSVDivider, "File", "Method", "Template", "Crop pixels", "Accuracy", "Transaction length", "Pollution percent", "Use mask", "WSM", "Limit", "SP") + Tools.Consts.CSVDivider;
                    log += string.Join(Tools.Consts.CSVDivider, "MM Orig", "MSE Orig", "DON Orig", "MM Pollute", "MSE Pollute", "DON Pollute", "MM Restored", "MSE Restored", "DON Restored", "Polluted count", "Find", "Miss", "False") + "\n";
                }
                log += string.Join(Tools.Consts.CSVDivider, args) + Tools.Consts.CSVDivider;
                log += string.Join(Tools.Consts.CSVDivider, metricsOrig, metricsPolluted, metricsRestored) + Tools.Consts.CSVDivider;
                log += dataMining.GetPollutionStatistics();

                StreamWriter fs = new StreamWriter("Statistics.csv", true);
                fs.WriteLine(log);
                fs.Close();

                //StreamWriter fs = new StreamWriter(args[0] + "_log.txt", false);
                //fs.WriteLine(log);
                //fs.Close();
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
            else
            {
                if (args[0] == "/s")
                {
                    var myImage = new MyImage();
                    myImage.Bitmap = new Bitmap(args[1]);
                    var dm = new DecisionMethods(myImage);

                    dm.SaveInMask = true;
                    dm.Pollute(decimal.Parse(args[2]), false);
                    var savedMask = Tools.ArrayTools.CopyArray <bool>(dm.PollutedMask);

                    dm.FindPixels(int.Parse(args[3]), double.Parse(args[4].Replace(".", ",")), double.Parse(args[5].Replace(".", ",")), int.Parse(args[6]) == 1);
                    var savedMask2 = Tools.ArrayTools.CopyArray <bool>(dm.PollutedMask);

                    bool addHeader = !File.Exists("Statistics_Mask.csv");

                    string       log = string.Empty;
                    StreamWriter fs  = new StreamWriter("Statistics_Mask.csv", true);
                    if (addHeader)
                    {
                        log += string.Join(Tools.Consts.CSVDivider, "File", "Pollution percent", "M", "N", "K", "Use color", "Use mask", "MR", "NR", "Broken", "Found", "Match", "Not found", "Wrong found", "MM Orig", "MSE Orig", "DON Orig", "MM Pollute", "MSE Pollute", "DON Pollute", "MM Restored", "MSE Restored", "DON Restored") + "\n";
                    }
                    log += string.Join(Tools.Consts.CSVDivider, args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]) + Tools.Consts.CSVDivider;
                    log += string.Join(Tools.Consts.CSVDivider, Tools.Metrics.MatrixDifference(savedMask, savedMask2, MetricsMode.CSVSimple));
                    fs.WriteLine(log);
                    fs.Close();
                }
                else if (args[0] == "/r")
                {
                    // Initialize
                    var myImage = new MyImage();
                    myImage.Bitmap = new Bitmap(args[1]);
                    var dm = new DecisionMethods(myImage);

                    var metricsOrig = dm.GetMetrics(MetricsMode.CSVSimple);

                    // Pollute
                    dm.SaveInMask = true;
                    dm.Pollute(decimal.Parse(args[2]), false);
                    var savedMask = Tools.ArrayTools.CopyArray <bool>(dm.PollutedMask);
                    dm.MyImage.Bitmap.Save(args[1] + "_polluted.png", ImageFormat.Png);

                    var metricsPolluted = dm.GetMetrics(MetricsMode.CSVSimple);

                    // Find Pixels
                    dm.SaveInMask = int.Parse(args[7]) == 1;
                    dm.FindPixels(int.Parse(args[3]), double.Parse(args[4].Replace(".", ",")), double.Parse(args[5].Replace(".", ",")), int.Parse(args[6]) == 1);
                    var savedMask2 = Tools.ArrayTools.CopyArray <bool>(dm.PollutedMask);
                    ImageTransform.BoolToBitmap(dm.PollutedMask).Save(args[1] + "_mask.png", ImageFormat.Png);

                    // Restore
                    var restoredImage   = dm.RestorePixels(int.Parse(args[8]), int.Parse(args[9]));
                    var metricsRestored = Tools.Metrics.GetUnifiedMetrics(restoredImage, MetricsMode.CSVSimple);
                    restoredImage.Bitmap.Save(args[1] + "_restore.png", ImageFormat.Png);

                    var restoredImageOld   = dm.RestorePixelsOld(4);
                    var metricsRestoredOld = Tools.Metrics.GetUnifiedMetrics(restoredImage, MetricsMode.CSVSimple);
                    restoredImageOld.Bitmap.Save(args[1] + "_restoreOld.png", ImageFormat.Png);

                    bool addHeader = !File.Exists("Statistics_Restore.csv");

                    string       log = string.Empty;
                    StreamWriter fs  = new StreamWriter("Statistics_Restore.csv", true);
                    if (addHeader)
                    {
                        log += string.Join(Tools.Consts.CSVDivider, "File", "Pollution percent", "M", "N", "K", "Use color", "Use mask", "MR", "NR", "Broken", "Found", "Match", "Not found", "Wrong found", "MM Orig", "MSE Orig", "DON Orig", "MM Pollute", "MSE Pollute", "DON Pollute", "MM Restored", "MSE Restored", "DON Restored", "MM Restored Old", "MSE Restored Old", "DON Restored Old") + "\n";
                    }
                    log += string.Join(Tools.Consts.CSVDivider, args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]) + Tools.Consts.CSVDivider;
                    log += string.Join(Tools.Consts.CSVDivider, Tools.Metrics.MatrixDifference(savedMask, savedMask2, MetricsMode.CSVSimple)) + Tools.Consts.CSVDivider;
                    log += metricsOrig + Tools.Consts.CSVDivider;
                    log += metricsPolluted + Tools.Consts.CSVDivider;
                    log += metricsRestored + Tools.Consts.CSVDivider;
                    log += metricsRestoredOld;
                    fs.WriteLine(log);
                    fs.Close();
                }
            }
        }