private void GenerateData()
        {
            string path = Directory.GetCurrentDirectory() + "\\";
            SegmentationData.MAX_SEGMENT_SIZE = 6;
            training = SegmentationData.GetTrainingData(path + "originals", path + "segments", path + "buildings", out originalImage, iteration++);
            trainingData = training.Vectors;
            idealData = training.Ideal;
            this.pictureBox1.Image = originalImage = training.OriginalImage;

            /*ImageForm imageForm = new ImageForm(training.OriginalImage);
            imageForm.Show();*/
            /*List<Bitmap> bitmaps = new List<Bitmap>();
            for (int i = 0; i < training.Vectors.Length; i++)
                if (idealData[i][0] == 1)
                    bitmaps.Add(SegmentationData.GetBitmapFromDoubleArray(training.Vectors[i]));
            SegmentsViewer segmentsViewer = new SegmentsViewer(bitmaps);
            segmentsViewer.ShowDialog();*/

            /*for (int i = 0; i < training.Segments.Length; i++)
            {
                for (int x = 0; x < training.Segments[i].Width; x++)
                {
                    for (int y = 0; y < training.Segments[i].Height; y++)
                    {
                        if (training.Segments[i].GetPixel(x,y).ToArgb() != Color.White.ToArgb())
                            originalImage.SetPixel(x + training.Positions[i].X, y + training.Positions[i].Y, training.Segments[i].GetPixel(x,y));
                    }
                }
            }
            ImageForm imageForm = new ImageForm(originalImage);
            imageForm.ShowDialog();*/

            for (int i = 0; i < training.Vectors.Length; i++)
            {
                for (int j = 0; j < training.Vectors[i].Length - 4; j++)
                {
                    if (training.Vectors[i][j] > 0)
                        training.Vectors[i][j] /= 255;
                }
            }
        }
        public static TrainingData GetTrainingData(string pathToOriginals, string pathToSegments, string pathToBuildings, out Bitmap originalImageRes, int iteration)
        {
            TrainingData trainingData = new TrainingData();
            originalImageRes = null;

            string[] originals = Directory.GetFiles(pathToOriginals);
            string[] segments = Directory.GetFiles(pathToSegments);
            string[] buildings = Directory.GetFiles(pathToBuildings);

            Array.Sort(originals, StringComparer.InvariantCulture);
            Array.Sort(segments, StringComparer.InvariantCulture);
            Array.Sort(buildings, StringComparer.InvariantCulture);

            List<double[]> segmentsList = new List<double[]>();
            List<double[]> idealList = new List<double[]>();

            if (originals.Length != segments.Length || originals.Length != buildings.Length)
                throw new NotImplementedException();

            for (int i = 0; i < originals.Length; i++)
            {
                if (i != iteration - 1)
                    continue;
                Dictionary<int, SegmentData> nrOfElementsInSegment = new Dictionary<int, SegmentData>();
                int[,] matrix = null;
                int average = int.MaxValue;

                Bitmap originalImage = originalImageRes = new Bitmap(originals[i]);
                Bitmap buildingsImage = new Bitmap(buildings[i]);
                Bitmap segmentsImage = LoadImage(segments[i], out matrix, out nrOfElementsInSegment, out average);

                /*Bitmap idealResult = new Bitmap(originalImage.Width, originalImage.Height);
                for (int x = 0; x < idealResult.Width; x++)
                    for (int y = 0; y < idealResult.Height; y++)
                        if (buildingsImage.GetPixel(x, y).ToArgb() != Color.White.ToArgb())
                            idealResult.SetPixel(x, y, originalImage.GetPixel(x, y));
                        else
                            idealResult.SetPixel(x, y, Color.White);
                ImageForm idealForm = new ImageForm(idealResult);
                idealForm.Text = "IDEAL RESULT";
                idealForm.ShowDialog();

                ImageForm segForm = new ImageForm(segmentsImage);
                segForm.ShowDialog();*/

                List<Point> points;
                List<Bitmap> segmentsImages;
                Tuple<List<double[]>, List<double[]>> result = LoadSegments(originalImage, buildingsImage, matrix, nrOfElementsInSegment, average, out points, out segmentsImages);
                trainingData.Positions = points.ToArray();
                trainingData.Segments = segmentsImages.ToArray();
                trainingData.OriginalImage = originalImage;
                trainingData.SegmentsImage = buildingsImage;
                segmentsList.AddRange(result.Item1);
                idealList.AddRange(result.Item2);
            }

            trainingData.Vectors = segmentsList.ToArray();
            trainingData.Ideal = idealList.ToArray();
            //int nrofbuildings = trainingData.Ideal.Where(x => x[0] == 1).Count();
            //Console.WriteLine(nrofbuildings);
            return trainingData;
        }