private void AppExit_Click(object sender, RoutedEventArgs e)
        {
            PrebuildSignsClassifier tc = new PrebuildSignsClassifier();
            List<Sign> result = tc.Teach();
            int num = tc.FindClass(new Sign(20,1, 27, 1,57));


            Application.Current.Shutdown();
        }
        private void PerformClassification(List<Bitmap> circles, List<Bitmap> triangles, List<Bitmap> rectangles, ImageViewModel viewModel)
        {
            var signData = new Dictionary<Bitmap, Sign>();

            foreach (var circle in circles)
            {
                var colorInfo = ColorInfo.Extract(circle);
                signData.Add(circle, new Sign(100, colorInfo[0], colorInfo[1], colorInfo[2], colorInfo[3]));
            }
            foreach (var triangle in triangles)
            {
                var colorInfo = ColorInfo.Extract(triangle);
                signData.Add(triangle, new Sign(50, colorInfo[0], colorInfo[1], colorInfo[2], colorInfo[3]));
            }
            foreach (var rectangle in rectangles)
            {
                var colorInfo = ColorInfo.Extract(rectangle);
                signData.Add(rectangle, new Sign(150, colorInfo[0], colorInfo[1], colorInfo[2], colorInfo[3]));
            }

            var containers = new[]
            {
                null, viewModel.WarningSigns, viewModel.ProhibitingSigns, viewModel.RegulatorySigns, viewModel.InformationSigns,
                viewModel.TemporarySigns
            };

            var tc = new PrebuildSignsClassifier();
            tc.Teach();
            foreach (var sign in signData)
            {
                var classIndex = tc.FindClass(sign.Value);
                var resizedImage = BilinearInterpolation.Resize(sign.Key, 150, 150);
                containers[classIndex].Add(new ImageModel(BitmapConverter.GetBitmapSource(resizedImage)));
            }
        }
        private void PerformClassification(List<Bitmap>[] circles, List<Bitmap>[] triangles, List<Bitmap>[] rectangles, ImageViewModel viewModel)
        {
            var signData = new Dictionary<Bitmap[], Sign>();

            for (int i = 0; i < circles[1].Count; i++)
            {
                var circle = circles[1][i];
                var colorInfo = ColorInfo.Extract(circle);
                signData.Add(new[] { circles[0][i] , circles[1][i] }, new Sign(100, colorInfo[0], colorInfo[1], colorInfo[2], colorInfo[3]));
            }
            for (int i = 0; i < triangles[1].Count; i++)
            {
                var triangle = triangles[1][i];
                var colorInfo = ColorInfo.Extract(triangle);
                signData.Add(new[] { triangles[0][i], triangles[1][i] }, new Sign(50, colorInfo[0], colorInfo[1], colorInfo[2], colorInfo[3]));
            }
            for (int i = 0; i < rectangles[1].Count; i++)
            {
                var rectangle = rectangles[1][i];
                var colorInfo = ColorInfo.Extract(rectangle);
                signData.Add(new[] { rectangles[0][i], rectangles[1][i] }, new Sign(150, colorInfo[0], colorInfo[1], colorInfo[2], colorInfo[3]));
            }

            var containers = new[]
            {
                viewModel.WarningSigns, viewModel.ProhibitingSigns, viewModel.RegulatorySigns, viewModel.InformationSigns,
                viewModel.TemporarySigns
            };

            var formatter = new BinaryFormatter();
            Stream stream = new FileStream("..\\..\\..\\perceptrons.bin", FileMode.Open, FileAccess.Read, FileShare.None);
            var perceptrons = (List<Perceptron>)formatter.Deserialize(stream);
            stream.Close();

            var tc = new PrebuildSignsClassifier();
            tc.Teach();
            var signsViewModel = (SignsGrid.DataContext) as SignViewModel;
            signsViewModel.Signs.Clear();

            foreach (var sign in signData)
            {
                var groupIndex = tc.FindClass(sign.Value) - 1;
                var signsImageSource = BitmapConverter.GetBitmapSource(sign.Key[1]);
                containers[groupIndex].Add(new ImageModel(signsImageSource));
                var perceptron = perceptrons[groupIndex];
                var histogram =
                    HistogramExtracter.Process(BilinearInterpolation.Resize(sign.Key[0], ResizeWidth, ResizeHeight));
                var classificationResult = perceptron.Classify(histogram).ToList();
                var classIndex = classificationResult.IndexOf(classificationResult.Max());
                var description = SignDescription.Get(groupIndex, classIndex);
                signsViewModel.Signs.Add(new SignModel(signsImageSource, description));

            }
        }