Beispiel #1
0
        private void Test()
        {
            string folderImport  = (string)TestFolderImportLabel.Content;
            string testImagePath = (string)ImageElectionLabel.Content;

            if (folderImport == "Not defined" || testImagePath == "Not defined")
            {
                System.Windows.MessageBox.Show("Invalid directory path");
                return;
            }

            Bitmap testImage = (Bitmap)Bitmap.FromFile(testImagePath);

            testImage = new Bitmap(testImage, AdvancedOptions._nBitmapSize, AdvancedOptions._nBitmapSize);

            object[] returned = DataHandler.ProcessInputTest(folderImport);

            if (returned == null)
            {
                return;
            }

            List <string> labels = (List <string>)returned[0];

            Cell[,] map = (Cell[, ])returned[1];

            lh = new LabelingHandler(labels);
            kn = new KohonenNetwork(testImage, lh, map);
        }
Beispiel #2
0
        private void Train()
        {
            string folderImport = (string)TrainFolderImportLabel.Content;
            string folderLabels = (string)TrainLabelImportLabel.Content;
            string folderSave   = (string)TrainFolderSaveLabel.Content;

            if (folderImport == "Not defined" || folderLabels == "Not defined" || folderSave == "Not defined")
            {
                System.Windows.MessageBox.Show("Invalid directory path");
                return;
            }

            object[] returned = DataHandler.ProcessInputTrain(folderImport, folderLabels);

            if (returned == null)
            {
                return;
            }

            List <string> labels     = (List <string>)returned[0];
            List <Bitmap> sourceData = (List <Bitmap>)returned[1];

            lh = new LabelingHandler(labels);

            kn = new KohonenNetwork(sourceData, lh, folderSave);

            started = true;
        }
        // -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        // Construction
        // -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        public KohonenNetwork(LabelingHandler labels, Cell[,] srcMap, ClassifyAnalytics classWindow)
        {
            lh = labels;

            map = srcMap;

            cw = classWindow;

            sourceData = new List <List <Bitmap> >();
        }
Beispiel #4
0
        // Trained version of the KohonenNetwork for it to be tested against a new input.
        // As such, the trained network must be added as a parameter

        public KohonenNetwork(Bitmap data, LabelingHandler labels, Cell[,] srcMap)
        {
            sourceData = new List <Bitmap> {
                data
            };
            lh = labels;

            map          = srcMap;
            outputFolder = null;

            Test_Network();
        }
Beispiel #5
0
        // Trained version of the KohonenNetwork for it to be tested against a new input.
        // As such, the trained network must be added as a parameter

        public KohonenNetwork(Bitmap data, LabelingHandler labels, Cell[,] srcMap, ClassifyAnalytics mainWindow)
        {
            sourceData = new List <Bitmap> {
                data
            };
            lh = labels;

            map          = srcMap;
            outputFolder = null;

            mw = mainWindow;

            Test_Network();
        }
Beispiel #6
0
        // Version of the KohonenNetwork for it to be trained

        public KohonenNetwork(List <Bitmap> data, LabelingHandler labels, string save)
        {
            sourceData = data;
            lh         = labels;

            Init_Map();

            thread = new Thread(Train_Network);
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            running = true;

            outputFolder = save;
        }
Beispiel #7
0
        public static void CreateOutput(string folder, Cell[,] map, LabelingHandler lh)
        {
            int mapHeight = map.GetLength(0);
            int mapWidth  = map.GetLength(1);

            string mapFolder = Path.Combine(folder, "Map");

            string[,] names = new string[mapHeight, mapWidth];
            int[,] labels   = new int[mapHeight, mapWidth];

            Directory.CreateDirectory(mapFolder);

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    names[i, j]  = i + "_" + j;
                    labels[i, j] = map[i, j].getIndex();

                    string dir = Path.Combine(mapFolder, i + "_" + j + ".bmp");
                    map[i, j].SaveAsBmp(dir);
                }
            }

            string[] labelNames   = lh.getConvertedLabels().ToArray();
            int[]    labelIndexes = lh.getConvertedIndexes().ToArray();

            using (XmlWriter writer = XmlWriter.Create(Path.Combine(folder, "metadata.xml")))
            {
                writer.WriteStartDocument();

                writer.WriteStartElement("Map");

                writer.WriteElementString("Height", mapHeight.ToString());
                writer.WriteElementString("Width", mapWidth.ToString());


                writer.WriteStartElement("LabelingHandler");
                writer.WriteElementString("Size", labelNames.Count().ToString());

                for (int i = 0; i < labelNames.Count(); i++)
                {
                    writer.WriteStartElement("Label");
                    writer.WriteElementString("Name", labelNames[i]);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();

                writer.WriteStartElement("CellMap");

                for (int i = 0; i < mapHeight; i++)
                {
                    for (int j = 0; j < mapWidth; j++)
                    {
                        writer.WriteStartElement("Cell");
                        writer.WriteElementString("Name", names[i, j]);
                        writer.WriteElementString("Label", labels[i, j].ToString());
                        writer.WriteEndElement();
                    }
                }
                writer.WriteEndElement();

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }